首页 > 其他分享 >POJ 1284 Primitive Roots

POJ 1284 Primitive Roots

时间:2022-11-09 19:40:52浏览次数:36  
标签:prime 1284 Primitive const int POJ ans include define


Description



We say that integer x, 0 < x < p, is a primitive root modulo odd prime p if and only if the set { (x  i mod p) | 1 <= i <= p-1 } is equal to { 1, ..., p-1 }. For example, the consecutive powers of 3 modulo 7 are 3, 2, 6, 4, 5, 1, and thus 3 is a primitive root modulo 7. 
Write a program which given any odd prime 3 <= p < 65536 outputs the number of primitive roots modulo p. 


Input



Each line of the input contains an odd prime numbers p. Input is terminated by the end-of-file seperator.


Output



For each p, print a single number that gives the number of primitive roots in a single line.


Sample Input



23 31 79


Sample Output



10 8

24


原根的个数是phi(phi(n))个,所以这题就求phi(n-1)即可。

#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define loop(i,j,k) for (int i = j;i != -1; i = k[i])
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
#define ff first
#define ss second
#define mp(i,j) make_pair(i,j)
#define pb push_back
#define pii pair<int,LL>
#define in(x) scanf("%d", &x);
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-4;
const int INF = 0x7FFFFFFF;
const int mod = 998244353;
const int N = 20;
int n;

int main()
{
while (scanf("%d", &n) != EOF)
{
--n; int ans = 1;
for (int i = 2; i*i <= n; i++)
{
if (n % i) continue;
n /= i; ans *= i - 1;
while (!(n % i)) ans *= i, n /= i;
}
printf("%d\n", n > 1 ? ans * (n - 1) : ans);
}
return 0;
}



标签:prime,1284,Primitive,const,int,POJ,ans,include,define
From: https://blog.51cto.com/u_15870896/5838598

相关文章

  • POJ 2407 Relatives
    DescriptionGivenn,apositiveinteger,howmanypositiveintegerslessthannarerelativelyprimeton?Twointegersaandbarerelativelyprimeifth......
  • POJ 3970 Party
    DescriptionTheCEOofACM(AssociationofCryptographicMavericks)organizationhasinvitedallofhisteamstotheannualall-handsmeeting,beingaver......
  • SPOJ LCS Longest Common Substring
    DescriptionAstringisfinitesequenceofcharactersoveranon-emptyfinitesetΣ.Inthisproblem,Σisthesetoflowercaseletters.Substring,alsocalled......
  • SPOJ LCS2 Longest Common Substring II
    DescriptionAstringisfinitesequenceofcharactersoveranon-emptyfinitesetΣ.Inthisproblem,Σisthesetoflowercaseletters.Substring,alsocalled......
  • POJ 3458 Colour Sequence
    DescriptionWehaveapileofcardsconsistingof100cardsthatarecolouredonbothsides.Thereisafinitenumberofcolours(atmost26).Inadditionthe......
  • SPOJ 705 New Distinct Substrings
    DescriptionGivenastring,weneedtofindthetotalnumberofitsdistinctsubstrings.InputT-numberoftestcases.T<=20;Eachtestcaseconsistsofonestr......
  • POJ 1743 Musical Theme
    DescriptionAmusicalmelodyisrepresentedasasequenceofN(1<=N<=20000)notesthatareintegersintherange1..88,eachrepresentingakeyonthepi......
  • 究竟什么是POJO?
    POJO(PlainOldJavaObject)这种叫法是MartinFowler、RebeccaParsons和JoshMacKenzie在2000年的一次演讲的时候提出来的。     我在做J2EE培训中发现我的......
  • POJ3061 Subsequence
    思路:尺取法注意本题目中所有的内容全部是证书,这就为我们维护了一个很好的单调性.考虑最暴力的\(\mathcalO(n^3)\)的做法,就是枚举起点,终点,然后分别求和.但是......
  • POJ-1018
    POJ-1018(现在好像过不了)题意目前有一个公司需要购进宽带设备,每种设备有多款机器供选择,每种设备都需购进一台,现给出每台设备的带宽p与价格q,要求选择设备的最小带宽\(min(......