2014-10-31 20:15:23

总结:这场有点怪怪的吧,a比b难,c不难,然后d题虽然知道怎么写,但就是tle - =!

A:求素数的原根个数,根据定理:如果正整数p是素数,那么其原根个数是phi(p-1),所以直接求一遍欧拉函数即可。12min(中速)

  (当然有人根据定义直接暴力检索也可以)

 1 /*************************************************************************
 2     > File Name: a.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com 
 5     > Created Time: Fri 31 Oct 2014 06:10:04 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <vector>
13 #include <map>
14 #include <set>
15 #include <stack>
16 #include <queue>
17 #include <iostream>
18 #include <algorithm>
19 using namespace std;
20 #define lp (p << 1)
21 #define rp (p << 1|1)
22 #define getmid(l,r) (l + (r - l) / 2)
23 #define MP(a,b) make_pair(a,b)
24 typedef long long ll;
25 const int INF = 1 << 30;
26 
27 int p;
28 
29 int main(){
30     scanf("%d",&p);
31     --p;
32     int ans = p;
33     int top = sqrt(1.0 * p);
34     for(int i = 2; i <= top; ++i) if(p % i == 0){
35         while(p % i == 0) p /= i;
36         ans = ans * (i - 1) / i;
37     }
38     if(p != 1) ans = ans * (p - 1) / p;
39     printf("%d\n",ans);
40     return 0;
41 }
View Code

相关文章:

  • 2021-12-12
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
相关资源
相似解决方案