CF284A Cows and Primitive Roots
这道题就是求一个奇素数\(p\)的原根数量。
公式是\(\varphi(\varphi(p))\)。又因为\(p\)是质数,所以就是\(\varphi(p - 1)\)。
(证明啥的我不会……)
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
//const int maxn = ;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
int n;
int phi(int n)
{
int ans = n;
for(int i = 2; i * i <= n; ++i)
if(n % i == 0)
{
ans = ans / i * (i - 1);
while(n % i == 0) n /= i;
}
if(n > 1) ans = ans / n * (n - 1);
return ans;
}
int main()
{
while(scanf("%d", &n) != EOF) write(phi(n - 1)), enter;
return 0;
}
CF284A Cows and Primitive Roots的更多相关文章
- 【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 原根
题目来源:POJ 1284 Primitive Roots 题意:求奇素数的原根数 思路:一个数n是奇素数才有原根 原根数是n-1的欧拉函数 #include <cstdio> const ...
- POJ 1284:Primitive Roots(素数原根的个数)
Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5709 Accepted: 3261 Descr ...
- POJ 1284 Primitive Roots 数论原根。
Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2479 Accepted: 1385 D ...
- poj 1284 Primitive Roots (原根)
Primitive Roots http://poj.org/problem?id=1284 Time Limit: 1000MS Memory Limit: 10000K Descr ...
- 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: ...
- poj 1284 Primitive Roots(未完)
Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3155 Accepted: 1817 D ...
- 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 ...
随机推荐
- 使用IndexOf方法来判断“咳嗽”出现的次数及索引、使用Dictionary<key,value> 集合统计没个字符出现的次数
static void Main(string[] args) { #region string str = "患者:医生我咳嗽的很严重,大夫:你多大年纪了? 患者:我75岁 大夫:那二十岁 ...
- vscode 安装插件,和相关配置
安装插件,配置对应的用户设置,进行替换,实现插件功能的生效 { // 控制是否在搜索中跟踪符号链接. "search.followSymlinks": false, "e ...
- 【转】如何用Maven创建web项目(具体步骤)
使用eclipse插件创建一个web project 首先创建一个Maven的Project如下图 我们勾选上Create a simple project (不使用骨架) 这里的Packing 选择 ...
- java语言的各种输入情况(ACM常用)
1.只输入一组数据: Scanner s=new Scanner(System.in); int a=s.nextInt(); int b=s.nextInt(); 2.输入有多组数据,没有说明输入几 ...
- 多线程拷贝备份文件方法(Windows)
D:\bat\robocopy.exe D:\backupdata \\192.168.36.45\BData\ db_20170716.dmp 解释: 微软提供的robocopy.exe命令,默 ...
- 数组的filter()方法
filter()也是一个用的不多的方法,但有时候还是比较有用的: 首先,Array.filter()是数组的方法,它作为数组方法被调用,传入一个callback,返回Array中符合callback条 ...
- csharp:Conversion Between DataTable and List
/// <summary> /// http://www.codeproject.com/Tips/784090/Conversion-Between-DataTable-and-List ...
- Hadoop & Spark & Hive & HBase
Hadoop: http://hadoop.apache.org/docs/r2.6.4/hadoop-project-dist/hadoop-common/SingleCluster.html bi ...
- Directly output the object name
package basic.java; public class Case { public static void main(String[] args) { Student s = new Stu ...
- C/C++标准有哪些?
1. C 时间 名称 标准制定组织 事件 1978 K&R标准 K&R <The C Programming Language> ...