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 ...
随机推荐
- layer子窗口与父窗口传值
layer作为优秀的jquery框架,可以用作弹出组件.日历.分页等,而且实现简单,只有几十k的大小. 此处给出弹出窗口时子窗口与父窗口的传值.js和css这里不展示引入(以下给出目录结构的图片),仅 ...
- js 千分位符号 正则方法
function toThousands(num) { return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');}
- .net core mvc 类库读取配置文件
appsettings.json,给类库项目引入 Microsoft.Extensions.Configuration 和 Microsoft.Extensions.Configuration.J ...
- [javaSE] GUI(对话框Dialog)
对话框不能单独存在,依赖于窗体,有显示标题,有模式 获取Dialog对象,new出来,构造参数:Frame对象,String的标题,模式 窗体内部的内容,Label对象,Button对象,调用Dial ...
- 【SSH网上商城项目实战08】查询和删除商品类别功能的实现
转自:https://blog.csdn.net/eson_15/article/details/51338991 上一节我们完成了使用DataGrid显示所有商品信息,这节我们开始添加几个功能:添加 ...
- MySQL 索引知识总结
将 mysql 的索引以书本的索引类比比较贴切,要找到一个关键字为xxx 的条目,首先翻到索引中查找有哪些页码涉及到,无疑就缩小了范围.在这个小范围内再寻找符合条件的数据,效率就会提高许多. mysq ...
- Excel2010条件格式的位置
以下是excel2010的条件格式设置方法(英文版) 具体使用方法可以参考 http://office.microsoft.com/zh-cn/excel-help/HA102809768.aspx
- JPA 实体映射
一.实体基本映射 /* * @Entity:将领域对象标注为一个实体,表示保存到数据库中 * @@Table:保存到数据库中表名,默认表名为类名,可通过name属性命名 * * */ @Entity ...
- [SD2015]序列统计——solution
http://www.lydsy.com/JudgeOnline/problem.php?id=3992 很容易得出DP方程: f[i][c]=f[i-1][a]*f[1][b]① 其中a*b%M=c ...
- JavaScript的进阶之路(七)客户端JavaScript知识点总结
一.客户端JavaScript主要是BOM DOM的操作和js脚本的兼容性.互用性.可访问性.安全性的应用.以及一些框架的引用. 二.BOM:浏览器对象模型 主要介绍window对象 1.定时器:se ...