国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Harmonic Number (II) [數(shù)學(xué)]

2019-11-08 03:19:06
字體:
供稿:網(wǎng)友

I was trying to solve PRoblem ‘1234 - Harmonic Number’, I wrote the following code

long long H( int n ) { long long res = 0; for( int i = 1; i <= n; i++ ) res = res + n / i; return res;}

Yes, my error was that I was using the integer divisions only. However, you are given n, you have to find H(n) as in my code.

Input

Input starts with an integer T (≤ 1000), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n < 231).

Output

For each case, print the case number and H(n) calculated by the code.

Sample Input

11 1 2 3 4 5 6 7 8 9 10 2147483647

Sample Output

Case 1: 1 Case 2: 3 Case 3: 5 Case 4: 8 Case 5: 10 Case 6: 14 Case 7: 16 Case 8: 20 Case 9: 23 Case 10: 27 Case 11: 46475828386

題解

發(fā)現(xiàn)一下規(guī)律就可以寫出o(n√) 的代碼了

#include<stdio.h>typedef long long LL;int main(){ int T;LL n; scanf("%d",&T); for(int t=1;t<=T;t++){ scanf("%lld",&n); LL l=2,r=n,ans=0; while(l<=n/l){ ans+=(r-n/l)*(l-1); r=n/l; ans+=n/l; l++; } for(LL i=l;i<=r;i++) ans+=n/l; printf("Case %d: %lld/n",t,ans+n); } return 0;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 吉木乃县| 闻喜县| 阿拉善左旗| 武胜县| 称多县| 麟游县| 正宁县| 龙陵县| 临邑县| 乌审旗| 毕节市| 锦州市| 彭州市| 河曲县| 哈巴河县| 乐清市| 西林县| 陆良县| 玉门市| 壤塘县| 洛川县| 揭西县| 大宁县| 拉萨市| 万源市| 霸州市| 卓资县| 蒙自县| 黄石市| 融水| 安顺市| 沛县| 普定县| 广宗县| 镇江市| 孟州市| 澄城县| 左云县| 庐江县| 炎陵县| 溆浦县|