欧拉(BC)

输入样例
1 1
2 1
3 2
输出样例
2
2
2
f(x)打表找规律的 fx=x+1,fn(x)=x+n+1;然后用欧拉公式
 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 
 5 __int64 euler(__int64 n)
 6 {
 7      __int64 i;
 8      __int64 res = n, a = n;
 9      for(i = 2;i*i <= a; ++i)
10      {
11          if(a%i == 0)
12          {
13              res -= res / i; 
14              while(a % i == 0) 
15              {
16                 a /= i;
17              }
18          }
19      }
20      if(a > 1) res -= res/a;//存在大于sqrt(a)的质因子
21      return res;
22 }
23 
24 int main()
25 {
26     __int64 n, x;
27     while (~scanf("%I64d%I64d", &n, &x))
28     {
29         __int64 ans = n + x + 1;
30         printf("%I64d\n", euler(ans));
31     }
32     return 0;
33 }

 


posted @ 2015-12-12 21:42  御心飞行  阅读(160)  评论(0编辑  收藏  举报