2305: Answer I 欧拉函数

 2305: Answer I


StatusIn/OutTIME LimitMEMORY LimitSubmit TimesSolved UsersJUDGE TYPE
stdin/stdout3s8192K733130Standard

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值