Exam
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 951 Accepted Submission(s): 411
Problem 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?
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.
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
1 3 6 10 15 21 28
Sample Output
Case 1: 1 Case 2: 7 Case 3: 25 Case 4: 53 Case 5: 95 Case 6: 161 Case 7: 246
代码:
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
__int64 n,ans,i,j,a,b,c,nn=1;
while(~scanf("%I64d",&n))
{
ans=0;
a=pow(n*1.0,1.0/3.0);
while(a*a*a<n)a++;
if(a*a*a>n)a--;
ans+=a;
for(i=1;i<=a;i++)
{
c=n/i;
b=sqrt(c*1.0);
while(b*b<c)
b++;
if(b*b>c)
b--;
ans+=(b-i+c/i-i)*3;
for(j=i+1;j<=b;j++)
ans+=(c/j-j)*6;
}
printf("Case %I64d: %I64d\n",nn++,ans);
}
return 0;
}