2305: Answer I 欧拉函数

 2305: Answer I

Status In/Out TIME Limit MEMORY Limit Submit Times Solved Users JUDGE TYPE
stdin/stdout 3s 8192K 733 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
#include<stdio.h>
int a[50001]={0};
int main()
{
    int n,k;
    a[1]=0,a[2]=1,a[3]=3;
    for(n=4;n<=50000;n++)
    {
        int b=n;k=2;
        int res=n;
        while(k*k<=n)
        {
            if(b%k==0)
            {
                res-=res/k;
                b/=k;
    while(b%k==0) b/=k;
            }
            if(b==1) break;
            k++;
        }
  if(b>1) res-=res/b;
  a[n]=a[n-1]+res;
    }
    while(scanf("%d",&n)==1)
    {
        printf("%d/n",2*a[n]+1);
    }
    return 0;
}

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