2305: Answer I 欧拉函数

StatusIn/OutTIME LimitMEMORY LimitSubmit TimesSolved UsersJUDGE TYPE
stdin/stdout3s8192K734130Standard

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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值