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 ...
随机推荐
- asp,对待绑定数据加序号列(DataSet)
string sql_sel = "select InS.ID as isID, InS.InventorySize , InS.MinValue,InS.MaxValue from Inv ...
- FE面试题库
一.HTML 序号 面试题目 难度等级 回答要点 H1 简述编写HTML需要注意哪些事项? ☆ DOCTYPE.charset.viewport.语义化.CSS与JS的位置.DOM层级.结构样式行为的 ...
- C# 请求Https
/// <summary> /// Get请求 /// </summary> /// <param name="Url"></param& ...
- 记一次线上Mysql数据库 宕机
从发现问题,到最后解决一共消耗两个半小时(7:30~10:00),报警电话16通,警察坐镇,未完待续 ......
- WPF月视图控件
简介 在做一个应用时,需要做成日历月视图的形式.自己做较麻烦,于是上网找找看,在CodeProject上发现了这个Quick and Simple WPF Month-view Calendar,可是 ...
- 撩课-Java每天5道面试题第26天
161.简述一下springMVC当中的视图解析器 请求处理方法执行完成后,最终返回一个 ModelAndView 对象 对于那些返回 String,View 或 ModeMap 等类型的处理方法 S ...
- [转]Shared——回调函数是什么
本文内容转自知乎 作者:no.body 链接:https://www.zhihu.com/question/19801131/answer/27459821 回调函数(callback)是什么? 什么 ...
- csharp: Double Convert To String
/// <summary> /// /// </summary> /// <param name="fl"></param> /// ...
- 如何在FineReport中解析数据库内XML文件
在数据库表中,其中字段XML所存的为xml格式数据在表xmltest中.那么在使用该表进行报表制作时,需要将存于xml字段中的值读取出来作为报表数据源. XML每条记录数据格式如下: <Fiel ...
- ASP.NET MVC学习笔记 第二天
创建视图 返回给客户端的HTML代码最好通过视图指定.视图都在Views文件夹中定义.ViewsDemo控制器的视图需要一个ViewsDemo子目录,这是视图的约定. 可以把多个控 ...