题目传送门

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. novaclient源码分析

    源码版本:H版 FAULT_OS_COMPUTE_API_VERSION = "1.1" 一.目录结构及概况 novaclient/ |---client.py --------- ...

  2. 为VSCODE添加右键菜单

    参考:https://blog.csdn.net/GreekMrzzJ/article/details/82194913 1.创建一个名为vscode.reg的空文本文件,填入下列内容 Windows ...

  3. NOIP模拟赛17

    5分.... T1 LOJ 计算几何瞎暴力 维护以下操作: 1.序列末尾加一个数 2.序列全体从小到大排序 3.查询区间和 4.序列全体异或一个数k 序列全体异或一个数,很明显是trie树 那么序列全 ...

  4. LintCode 395: First Will Win 2

    LintCode 395: First Will Win 2 题目描述 有 n 个不同价值的硬币排成一条线.两个参赛者轮流从左边依次拿走 1 或 2 个硬币,直到没有硬币为止.计算两个人分别拿到的硬币 ...

  5. JS中函数void()

    <a href="javascript:void(0)">hello</a>/* * JS中函数void()的运用大体是这种新式; * void()是运算符 ...

  6. 分享6款国内、外开源PHP轻论坛CMS程序

    第一.Startbbs Startbbs,一款国产个人兴趣分享的轻论坛程序,采用PHP+MYSQL架构,目前版本是V1.1.5,之前我也 有搭建使用过功能还是比较简单的,默认风格比较让普通用户接受,这 ...

  7. Python3 断言

    #!/usr/bin/env python # _*_ coding:utf-8 _*_ # Author:CarsonLi ''' 断言一般用于后面有非常重要的操作,需要使用前面的数据,而且不容许出 ...

  8. C# 获取mp3文件的歌曲时间长度

    添加命名空间:    using Shell32;    using System.Text.RegularExpressions;添加引用:COM组件的Microsoft Shell Control ...

  9. HDU 6205 2017沈阳网络赛 思维题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6205 题意:给你n堆牌,原本每一堆的所有牌(a[i]张)默认向下,每次从第一堆开始,将固定个数的牌(b ...

  10. 当while read line 遇到 ssh

    问题:while read line 中使用ssh只能读取一行? #!/bin/sh while read line do echo $line ssh root@$line "echo 1 ...