2305: Answer I 欧拉函数

Status In/Out TIME Limit MEMORY Limit Submit Times Solved Users JUDGE TYPE
stdin/stdout 3s 8192K 734 130 Standard

Consider a scenario where you are asked to calculate a function Answer(x, y), with x and y both integers in the range [1, N], 1 <= N <= 50000. If you know Answer(x, y), then you can easily derive Answer(k*x, k*y) for any integer k. In this situation you want to know how many values of Answer(x, y) you need to precalculate. The function Answer is not symmetric.

For example, if N = 4, you need to precalculate 11 values: Answer(1, 1), Answer(1, 2), Answer(2, 1), Answer(1, 3), Answer(2, 3), Answer(3, 2), Answer(3, 1), Answer(1, 4), Answer(3, 4), Answer(4, 3) and Answer(4, 1).

Input

Each line will has a positive integer N.

Output

Only one integer that is how many values of Answer(x, y) you need to precalculate.

Sample Input

4

Sample Output

11

 

Problem Source: kscinow

 #include<stdio.h>
#include<math.h>
int a[50001];
int main()
{
 freopen("in.txt","r",stdin);
 freopen("out.txt","w",stdout);
 int n,res,m,i;
 a[1]=0;a[2]=1;a[3]=3;
 for(n=4;n<=50000;n++)
 {
   res=n;
   m=n;
   i=2;
   while(res>1&&i*i<=n)
   {
  if(res%i==0) m-=m/i;
  while(res%i==0)
   res=res/i;
  i++;
   }
   if(res>1) m-=m/res;
   a[n]=a[n-1]+m;
 }
 while(scanf("%d",&n)!=EOF)
    printf("%d/n",2*a[n]+1);
 return 0;
}

 

你可能感兴趣的:(function,Integer,input,output)