【题目大意】

给你一个素数n,求n的原根个数。

【题解】

关于原根有一个定理:

定理:如果模有原根,那么它一共有个原根。

所以这题就是求phi[phi[n]]

很简单吧。。。(如果知道这个定理的话)

 /**************
POJ 1284
by chty
2016.11.10
**************/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
using namespace std;
#define FILE "read"
#define MAXN 70010
int n,cnt,prime[MAXN],isprime[MAXN],phi[MAXN];
inline int read()
{
int x=,f=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-; ch=getchar();}
while(isdigit(ch)) {x=x*+ch-''; ch=getchar();}
return x*f;
}
void get()
{
phi[]=;
for(int i=;i<=;i++)
{
if(!isprime[i]) prime[++cnt]=i,phi[i]=i-;
for(int j=;j<=cnt&&prime[j]*i<=;j++)
{
isprime[prime[j]*i]=;
if(i%prime[j]==) {phi[prime[j]*i]=phi[i]*prime[j];break;}
else phi[prime[j]*i]=phi[i]*(prime[j]-);
}
}
}
int main()
{
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
get();
while(~scanf("%d",&n)) printf("%d\n",phi[phi[n]]);
return ;
}

【POJ1284】Primitive Roots的更多相关文章

  1. 【POJ1284】Primitive Roots 欧拉函数

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

  2. 【HDU 4992】 Primitive Roots (原根)

    Primitive Roots   Description We say that integer x, 0 < x < n, is a primitive root modulo n i ...

  3. 【poj 1284】Primitive Roots(数论--欧拉函数 求原根个数){费马小定理、欧拉定理}

    题意:求奇质数 P 的原根个数.若 x 是 P 的原根,那么 x^k (k=1~p-1) 模 P 为1~p-1,且互不相同. (3≤ P<65536) 解法:有费马小定理:若 p 是质数,x^( ...

  4. POJ1284:Primitive Roots——题解

    http://poj.org/problem?id=1284 给一个奇质数p,求p的原根数量. 有一个结论:当正整数n存在原根时,其一共有phi(phi(n))个不同余的原根. 所以答案为phi(p- ...

  5. POJ_1284 Primitive Roots 【原根性质+欧拉函数运用】

    一.题目 We say that integer x, 0 < x < p, is a primitive root modulo odd prime p if and only if t ...

  6. poj1284 Primitive Roots

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4775   Accepted: 2827 D ...

  7. POJ1284 Primitive Roots [欧拉函数,原根]

    题目传送门 Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5434   Accepted:  ...

  8. Primitive Roots(poj1284)

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3928   Accepted: 2342 D ...

  9. Primitive Primes - 题解【数学】

    题面 It is Professor R's last class of his teaching career. Every time Professor R taught a class, he ...

随机推荐

  1. java基础--关键字

  2. container-diff 谷歌开源镜像分析工具使用

    1. 安装 curl -LO https://storage.googleapis.com/container-diff/latest/container-diff-linux-amd64 & ...

  3. How to install torcs package in Debian

    Installation instructions Installing torcs package in Debian Wheezy is as easy as running: 没想到在debia ...

  4. 13.Python接口自动化测试 -- 豆瓣

    1.代码如下所示: import requests,unittest import json import HTMLTestRunner class TestDouBan(unittest.TestC ...

  5. 相关TableLayoutPanel分页显示自定义控件

    public partial class AcrossGrid : UserControl { /// <summary> /// 一页数量 /// </summary> ; ...

  6. 函数参数个数不确定时使用va_start

    今天在网上看程序时忽然发现别人的函数参数中有省略号,甚是吃惊,发现其函数中使用了va_start,经过查资料大概明白其用法,个人觉得很好用! #include <stdio.h> #inc ...

  7. javascript基础-js继承

    1.prototype方式 示例:没有使用prototype(下列这些代码只能获取array1数组的总和,而无法对array2数据进行求和) var array1 = new Array(1,4,9, ...

  8. FPGA的CNN加速,你怎么看?

    网上对于FPGACNN加速的研究已经很多了,神经网络的硬件加速似乎已经满大街都是了,这里我们暂且不讨论谁做的好谁做的不好,我们只是根据许许多多的经验来总结一下实现硬件加速,需要哪些知识,考虑哪些因素. ...

  9. Java 父类、静态、子类执行顺序

    顺序: 父类的静态,子类静态,父类非静态,父类构造方法,子类非静态,子类构造方法. public class A { static String name = "cjj"; int ...

  10. PyQt 5的基本功能

    PyQt5常用的模块 PyQt5的类别分为几个模块,包括: QtCore:包含非核心的GUI功能,此模块用于处理时间.文件和目录.各种数据类型.流.URL.MIME类型.线程或进程 QtGui:包括窗 ...