题目传送门

Primitive Roots
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 5434   Accepted: 3072

Description

We say that integer x, 0 < x < p, is a primitive root modulo odd prime p if and only if the set { (xi 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

  分析:

  一句话题意:求原根的个数。

  首先,如果知道原根的相关知识,那就可以直接上欧拉函数的板子了。关于原根的知识,请参考这里

  Code:

//It is made by HolseLee on 11th July 2018
//POJ 1284
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<iomanip>
using namespace std;
const int N=1e5+;
int n,phi[N],top,q[];
bool vis[N];
void ready()
{
phi[]=;
for(int i=;i<N;i++){
if(!vis[i])phi[q[++top]=i]=i-;
for(int j=,k;j<=top&&(k=i*q[j])<N;j++){
vis[k]=true;
if(i%q[j])phi[k]=phi[i]*(q[j]-);
else {phi[k]=phi[i]*q[j];break;}
}
}
}
int main()
{
ios::sync_with_stdio(false);
ready();
while(cin>>n){
printf("%d\n",phi[n-]);}
return ;
}

POJ1284 Primitive Roots [欧拉函数,原根]的更多相关文章

  1. POJ 1284 Primitive Roots (欧拉函数+原根)

    <题目链接> 题目大意: 满足{ ( $x^{i}$ mod p) | 1 <=$i$ <= p-1 } == { 1, …, p-1 }的x称为模p的原根.给出p,求原根个数 ...

  2. (Relax 数论1.8)POJ 1284 Primitive Roots(欧拉函数的应用: 以n为模的本原根的个数phi(n-1))

    /* * POJ_2407.cpp * * Created on: 2013年11月19日 * Author: Administrator */ #include <iostream> # ...

  3. 【POJ1284】Primitive Roots 欧拉函数

    题目描述: 题意: 定义原根:对于一个整数x,0<x<p,是一个mod p下的原根,当且仅当集合{ (xi mod p) | 1 <= i <= p-1 } 等于{ 1, .. ...

  4. poj1284(欧拉函数+原根)

    题目链接:https://vjudge.net/problem/POJ-1284 题意:给定奇素数p,求x的个数,x为满足{(xi mod p)|1<=i<=p-1}={1,2,...,p ...

  5. poj1284:欧拉函数+原根

    何为原根?由费马小定理可知 如果a于p互质 则有a^(p-1)≡1(mod p)对于任意的a是不是一定要到p-1次幂才会出现上述情况呢?显然不是,当第一次出现a^k≡1(mod p)时, 记为ep(a ...

  6. poj1284 && caioj 1159 欧拉函数1:原根

    这道题不知道这个定理很难做出来. 除非暴力找规律. 我原本找的时候出了问题 暴力找出的从13及以上的答案就有问题了 因为13的12次方会溢出 那么该怎么做? 快速幂派上用场. 把前几个素数的答案找出来 ...

  7. 数学之欧拉函数 &几道poj欧拉题

    欧拉函数总结+证明 欧拉函数总结2 POJ 1284 原根 #include<iostream> #include<cstdio> #include<cstring> ...

  8. hdu2588 GCD (欧拉函数)

    GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数.  (文末有题) 知 ...

  9. BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2553  Solved: 1565[Submit][ ...

随机推荐

  1. 关于NuGet

    一.NuGet是什么? NuGet是Microsoft开发平台的程序集包管理器,它由客户端工具和服务端站点组成,客户端工具提供给用户管理和安装/卸载软件程序包,以及打包和发布程序包到NuGet服务端站 ...

  2. 强制换行CSS样式

    语法: word-wrap : normal | break-word 取值: normal :? 默认值.允许内容顶开指定的容器边界 break-word :? 内容将在边界内换行.如果需要,词内换 ...

  3. 【BZOJ】1537: [POI2005]Aut- The Bus

    [算法]DP+线段树求区间max(二维偏序) [题解] 状态转移方程:f[i]=max(f[j]+v[i]),x[j]<x[i]&&y[j]<y[i]. 观察j的条件限制显 ...

  4. 【BZOJ】3143: [Hnoi2013]游走 期望+高斯消元

    [题意]给定n个点m条边的无向连通图,每条路径的代价是其编号大小,每个点等概率往周围走,要求给所有边编号,使得从1到n的期望总分最小(求该总分).n<=500. [算法]期望+高斯消元 [题解] ...

  5. gcc 随笔

    将几个文件编译成一个动态库 libtest.so gcc test_a.c test_b.c test_c.c -fPIC -shared -o libtest.so 将test.c与动态库libte ...

  6. HDU 1059 Dividing (dp)

    题目链接 Problem Description Marsha and Bill own a collection of marbles. They want to split the collect ...

  7. IE6透明PNG解决方案

    IE6不支持PNG-24图片一直困扰很多人,但是可以通过IE的独有的滤镜来解决,解决的方案很多,比如:将滤镜写在CSS里,还可以写成单独的 Javascript文件,本来认为推荐两种做法:第一种,将所 ...

  8. 使用ctypes在Python中调用C++动态库

    使用ctypes在Python中调用C++动态库 入门操作 使用ctypes库可以直接调用C语言编写的动态库,而如果是调用C++编写的动态库,需要使用extern关键字对动态库的函数进行声明: #in ...

  9. 73.Vivado使用误区与进阶——在Vivado中实现ECO功能

    关于Tcl在Vivado中的应用文章从Tcl的基本语法和在Vivado中的应用展开,继上篇<用Tcl定制Vivado设计实现流程>介绍了如何扩展甚至是定制FPGA设计实现流程后,引出了一个 ...

  10. python使用requests模块模拟登陆知乎

    from bs4 import BeautifulSoup import requests import time def captcha(captcha_data): with open(" ...