• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

.yin

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

D - Staircase Sequences

传送门:https://atcoder.jp/contests/abc190/tasks/abc190_d

题目大意

求有多少个连续的数相加等于n

1<=n<=1e121<=n<=1e12

题目思路

定义sum[l,r]=l+(l+1)+.....(r-1)+r

首先假设所有连续的数都是正数,那么为sum[l,r]=n,那么显然sum[-l+1,r]=n

然后直接枚举长度len,那么sum[1,len]可以求出来

就是 1到 len求和以后 每往后移一位就是加 len 所以只要用 n剪掉sum[1,len] 看能不能被len整除就行了

#include<stdio.h> 
int main()
{
      long long n,i,sum,ans=0;
    scanf("%lld",&n);
    for(i=1;i<=1e7;i++){
        sum=(1+i)*i/2;
        if(sum>n) break;
        if((n-sum)%i==0) ans+=2;
    }
    printf("%lld\n",ans);
}

 

posted on 2021-01-31 16:32  .yin  阅读(60)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3