首页 > 其他 > 详细

LightOJ 1245 Harmonic Number (II) 水题

时间:2016-04-12 22:29:10      阅读:302      评论:0      收藏:0      [点我收藏+]

分析:一段区间的整数除法得到的结果肯定是相等的,然后找就行了,每次是循环一段区间,暴力

技术分享
#include <cstdio>
#include <iostream>
#include <ctime>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=5e4+5;
const int INF=0x3f3f3f3f;
int main()
{
    int cas=0,T;
    scanf("%d",&T);
    while(T--){
      LL n;
      scanf("%lld",&n);
      LL ans=n;
      for(LL i=2;i<=n;++i){
        LL tmp=n/i;
        LL pos=n/tmp;
        ans=ans+(pos-i+1)*tmp;
        i=pos;
      }
      printf("Case %d: %lld\n",++cas,ans);
    }
    return 0;
}
View Code

 

LightOJ 1245 Harmonic Number (II) 水题

原文:http://www.cnblogs.com/shuguangzw/p/5384650.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!