2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > hdu4473 Exam

hdu4473 Exam

时间:2020-02-28 03:55:57

相关推荐

hdu4473  Exam

ExamTime Limit:10000MSMemory Limit:32768KB64bit IO Format:%I64d & %I64u Submit Status

Description

Rikka is a high school girl suffering seriously from Chūnibyō (the age of fourteen would either act like a know-it-all adult, or thinks they have special powers no one else has. You might google it for detailed explanation) who, unfortunately, performs badly at math courses. After scoring so poorly on her maths test, she is faced with the situation that her club would be disband if her scores keeps low.

Believe it or not, in the next exam she faces a hard problem described as follows.

Let’s denote f(x) number of ordered pairs satisfying (a * b)|x (that is, x mod (a * b) = 0) where a and b are positive integers. Given a positive integer n, Rikka is required to solve for f(1) + f(2) + . . . + f(n).

According to story development we know that Rikka scores slightly higher than average, meaning she must have solved this problem. So, how does she manage to do so?

Input

There are several test cases.

For each test case, there is a single line containing only one integer n (1 ≤ n ≤ 10 11).

Input is terminated by EOF.

Output

For each test case, output one line “Case X: Y” where X is the test case number (starting from 1) and Y is the desired answer.

Sample Input

13610152128

Sample Output

Case 1: 1Case 2: 7Case 3: 25Case 4: 53Case 5: 95Case 6: 161Case 7: 246我们可以发现,从1到n加起来,不就刚好把1-n全取到了么?这样就可以转化为a*b*c的组数,这样不就so easy了!但还有点小细节看程序

#include <iostream>#include <math.h>#include <stdio.h>using namespace std;__int64 mypow(__int64 x,__int64 a)//x的a次方根{__int64 m=pow(x,1.0/a),i,j,sum;//先用系统函数把大概范围求出来!while(1){sum=1;for(j=0;j<a;j++){sum*=m;}if(sum<=x){m++;}else{break;}}while(1){sum=1;for(j=0;j<a;j++){sum*=m;}if(sum>x)//这没有=号{m--;}else{return m;}}}int main(){__int64 n,i,j,k,sum,iall,jall,ni;int tcase=1;while(scanf("%I64d",&n)!=EOF){iall=mypow(n,3);jall=mypow(n,2);sum=iall;//iii这种形式的刚好是iall个for(i=1;i<=iall;i++){ni=n/i;//加快速度k=mypow(ni,2);sum+=(ni/i+k-2*i)*3;//iij的个数为ni/i-i;ijj这种形式的个数为k-i个for(j=i+1;j<=k;j++)//可以推出j小于根号下(n/i)这样速度更快{sum+=(ni/j-j)*6;}}printf("Case %d: %I64d\n",tcase++,sum);}return 0;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。