【POJ1284】Primitive Roots
【题目大意】
给你一个素数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的更多相关文章
- 【POJ1284】Primitive Roots 欧拉函数
题目描述: 题意: 定义原根:对于一个整数x,0<x<p,是一个mod p下的原根,当且仅当集合{ (xi mod p) | 1 <= i <= p-1 } 等于{ 1, .. ...
- 【HDU 4992】 Primitive Roots (原根)
Primitive Roots Description We say that integer x, 0 < x < n, is a primitive root modulo n i ...
- 【poj 1284】Primitive Roots(数论--欧拉函数 求原根个数){费马小定理、欧拉定理}
题意:求奇质数 P 的原根个数.若 x 是 P 的原根,那么 x^k (k=1~p-1) 模 P 为1~p-1,且互不相同. (3≤ P<65536) 解法:有费马小定理:若 p 是质数,x^( ...
- POJ1284:Primitive Roots——题解
http://poj.org/problem?id=1284 给一个奇质数p,求p的原根数量. 有一个结论:当正整数n存在原根时,其一共有phi(phi(n))个不同余的原根. 所以答案为phi(p- ...
- 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 ...
- poj1284 Primitive Roots
Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4775 Accepted: 2827 D ...
- POJ1284 Primitive Roots [欧拉函数,原根]
题目传送门 Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5434 Accepted: ...
- Primitive Roots(poj1284)
Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3928 Accepted: 2342 D ...
- Primitive Primes - 题解【数学】
题面 It is Professor R's last class of his teaching career. Every time Professor R taught a class, he ...
随机推荐
- lapis 集成openresty最新版本cjson 问题的解决
备注: 为了解决安装了lapis.同时又希望使用新版nginx 以及openresty 的特性(stream ...) 1. 解决方法 参考: https://github.com/leaf ...
- springboot使用hibernate validator校验方式
一.参数校验 在开发中经常需要写一些字段校验的代码,比如字段非空,字段长度限制,邮箱格式验证等等,写这些与业务逻辑关系不大的代码个人感觉有两个麻烦: 验证代码繁琐,重复劳动 方法内代码显得冗长 每次要 ...
- 在 FastAdmin 中启动 ThinkPHP 5 的请求缓存分析
在 FastAdmin 中启动 ThinkPHP 5 的请求缓存分析 缓存的基础配置 ThinkPHP 5 中有一个请求缓存:1 'request_cache' => true, 'reques ...
- 将 PCB 文件转换为可读的文本
将 PCB 文件转换为可读的文本 将元件转成列表. 坐标也放到列表中. 以元件号为排序. 使用 json 格式,并格式,方便对比. 元件网络转成单独文件. 特殊说明生成单独文件.
- [LeetCode系列]卡特兰数(Catalan Number) 在求解独特二叉搜寻树(Unique Binary Search Tree)中的应用分析
本文原题: LeetCode. 给定 n, 求解独特二叉搜寻树 (binary search trees) 的个数. 什么是二叉搜寻树? 二叉查找树(Binary Search Tree),或者是一棵 ...
- PHP RSA加签的实现过程
一.得到私钥文件mycert.key 2.从pfx提取密钥信息,并转换为key格式(pfx使用pkcs12模式补足) (1)提取密钥对 openssl pkcs12 -in 1.pfx -nocert ...
- openOffice转换的时候乱码在linux下使用openOffice的时候发现在转换后出现了乱码
openOffice转换的时候乱码 在linux下使用openOffice的时候发现在转换后出现了乱码,最后上网查了一下,按照网上的说法去试了试,最后也没有解决,也可能是我这边的linux的权限问题, ...
- C#实现 OPC历史数据存取研究
来源:http://blog.csdn.net/gjack/article/details/5641794 C#实现 OPC历史数据存取研究 (原文)Research of Accessing the ...
- JFreeChart API 说明(转)
原地址 http://blog.csdn.net/mike_caoyong/article/details/7338160 JFreeChart目前是最好的java图形解决方案,基本能够解决目前的图形 ...
- Socket客户端
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...