HDU 4473 HDOJ Exam (推理,5级)

Exam

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 590    Accepted Submission(s): 250


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?
 

Input
There are several test cases.
For each test case, there is a single line containing only one integer n (1 ≤ n ≤ 1011).
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
 

Source
 

Recommend
liuyiding

思路:

定义f(x) = 满足(a * b)|x的有序对(a,b)的个数。

  然后输入一个n,求f(1) + f(2) + ... + f(n)

  把原题的条件(a * b)|x 转化为 a * b * y = x

  然后就很好计算了,就是,输入一个n,计算有多少有序对(a, b ,y)满足a*b*y<=n

  不妨设a<=b<=y

  则,a<=n^(1/3) , b<=sqrt(n/a)

  那么

    对于三个数字都相同的情况,只计算一次: i i i

    对于三个数字中有两个相同的情况,计算3次: i i j, i j i, j i i

    对于均不相同的情况,计算6次: a b y ,a y b ,b a y ,b y a, y a b ,y b a

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define clr(f,z) memset(f,z,sizeof(f))
#define LL long long
using namespace std;
LL pow2(LL n)
{
  LL m=pow(n,0.5);
  while(m*m<=n)++m;
  while(m*m>n)--m;
  return m;
}
LL pow3(LL n)
{
  LL m=pow(n,1.0/3);
  while(m*m*m<=n)++m;
  while(m*m*m>n)--m;
  return m;
}
int main()
{
  LL cas=0,ans,n;
  while(~scanf("%I64d",&n))
  {
    LL m=pow3(n);ans=m;///i*i*i==k
    FOR(i,1,m)
    {
      LL ni=n/i;LL z=pow2(ni);
      ans+=(ni/i-i)*3;///i*i*j==k;i<j;
      ans+=(z-i)*3;///i*j*j==k;i<j
      FOR(k,i+1,z)
      ans+=(ni/k-k)*6;
    }
    printf("Case %I64d: %I64d\n",++cas,ans);
  }
}




posted @ 2013-10-03 19:18  剑不飞  阅读(203)  评论(0编辑  收藏  举报