hdu 1787(欧拉函数+水题)

题意:给出一个n,求大于0小于n的所有与n不互质的数的个数,欧拉函数模板题

 1 #include<iostream>
 2 #include<string.h>
 3 #include<string>
 4 #include<sstream>
 5 #include<vector>
 6 #include<deque>
 7 #include<map>
 8 #include<algorithm>
 9 #include<iomanip>
10 #include<math.h>
11 #include<set>
12 using namespace std;
13 
14 typedef long long ll;
15 typedef unsigned long long ull;
16 
17 int n;
18 ll Eular(ll n)
19 {
20     if (n == 1)
21         return 1;
22     ll res = n;
23     for (int i = 2; i <= sqrt(n); i++)
24     {
25         if (n%i == 0)
26         {
27             res = res / i * (i - 1);
28             while (n%i == 0)
29             {
30                 n = n / i;
31             }
32         }
33     }
34     if (n != 1)
35         res = res / n * (n - 1);
36     return res;
37 }
38 int main()
39 {
40     while (cin >> n&&n)
41     {
42         cout << n - 1 -Eular(n)<< endl;
43     }
44     return 0;
45 }

 

posted on 2019-02-16 16:01  QingFengDaHui  阅读(92)  评论(0编辑  收藏  举报

导航