HDU 2619 完全剩余类 原根】的更多相关文章

求有多少$i(<=n-1)$,使 $x^i  \mod n$的值为$[1,n-1]$,其实也就是满足完全剩余类的原根数量.之前好像在二次剩余的讲义PPT里看到这个过. 直接有个定理,如果模k下有原根,那么其原根总数为$\varphi(\varphi(k))$ /** @Date : 2017-09-21 19:22:16 * @FileName: HDU 2619 原根 完全剩余类.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@…
模板题,可用于求一个数的所有原根. #include<bits/stdc++.h> using namespace std; typedef long long ll; ,inf=0x3f3f3f3f; int n,fac[N],nf; vector<int> ans; int Pow(int x,int p,int mod) { ; ,x=(ll)x*x%mod))ret=(ll)ret*x%mod; return ret; } int phi(int x) { int ret=…
Primitive Roots   Description We say that integer x, 0 < x < n, is a primitive root modulo n if and only if the minimum positive integer y which makes x y = 1 (mod n) true is φ(n) .Here φ(n) is an arithmetic function that counts the totatives of n,…
转载自:大牛 知道一个定理了 a ^ x = y (mod p) ===>>   logd(a) * x = logd(y) (mod O(p) )      d 为 p 的 原根,  O(p) 是欧拉函数值 好难的题………..…
题目大意: 设\(f(i)\)为使\((x+y)^i \equiv x^i (mod\ p)\)成立的(x,y)的对数.其中\(1 \leq x \leq p-1 , 1\leq y\leq m\),m,p给定且p是一个质数.求\(\sum_{i=1}^{p-1}i*f(i)\),p<=1e9+7,m<=p-1 思路 我们考虑用原根去代换x,y. 设g为p的一个原根,\(g^a\equiv x(mod \ p),g^b \equiv y(mod \ p)\). 然后我们用\(g\)去代换\(x…
题目链接 大题流程: 判定是否有原根->求出最小原根->利用最小原根找出全部原根 #include<bits/stdc++.h> using namespace std; typedef long long LL; ; ]; ]; ]; int num_prime; void init() { memset(check, false, sizeof(check)); phi[]=; ; i<=maxn; i++) { if(!check[i]) { prime[num_pri…
The Children's Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends. Now I introduce the game to you. Suppose there are N people played the…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4992 题意:给出n,输出n的所有原根. 思路:求出n的一个原根x,那么对于所以的i,i<phi(n)且(i,phi(n))=1,x^i%n都是n的原根. int Euler(int n) { int i,ans=n; for(i=2;i*i<=n;i++) if(n%i==0) { ans=ans/i*(i-1); while(n%i==0) n/=i; } if(n>1) ans=ans/…
题目链接:hdu 4861 Couple doubi 题目大意:两个人进行游戏,桌上有k个球,第i个球的值为1i+2i+⋯+(p−1)i%p,两个人轮流取,假设DouBiNan的值大的话就输出YES,否则输出NO. 解题思路: 首先是DouBiNan先取,所以肯定优先选取剩余中值最大的,于是不存在说DouBiNan值小的情况,仅仅有大于和小于. 然后,对于val(i)=1i+2i+⋯+(p−1)i%p来说,仅仅有当i=ϕ(p)=p−1(p为素数)时,val(i)=p−1,其它情况下val(i)=…
Primitive Roots Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 583    Accepted Submission(s): 144 Problem Description We say that integer x, 0 < x < n, is a primitive root modulo n if and only…