嘟嘟嘟

这道题就是求一个奇素数\(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的更多相关文章

  1. 【HDU 4992】 Primitive Roots (原根)

    Primitive Roots   Description We say that integer x, 0 < x < n, is a primitive root modulo n i ...

  2. POJ 1284 Primitive Roots 原根

    题目来源:POJ 1284 Primitive Roots 题意:求奇素数的原根数 思路:一个数n是奇素数才有原根 原根数是n-1的欧拉函数 #include <cstdio> const ...

  3. POJ 1284:Primitive Roots(素数原根的个数)

    Primitive Roots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5709 Accepted: 3261 Descr ...

  4. POJ 1284 Primitive Roots 数论原根。

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2479   Accepted: 1385 D ...

  5. poj 1284 Primitive Roots (原根)

    Primitive Roots http://poj.org/problem?id=1284 Time Limit: 1000MS   Memory Limit: 10000K       Descr ...

  6. poj1284 Primitive Roots

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4775   Accepted: 2827 D ...

  7. POJ1284 Primitive Roots [欧拉函数,原根]

    题目传送门 Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5434   Accepted:  ...

  8. poj 1284 Primitive Roots(未完)

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3155   Accepted: 1817 D ...

  9. 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 ...

随机推荐

  1. 如何在没有https环境下使用webrtc

    新版本的webrtc使用需要Https,但是在内网开发调试时,要配置Https环境比较麻烦,下面的方法是教你如何在http下使用webrtc 1,点桌面上的Chrome图票,右键->属性,把目票 ...

  2. 十一、spark SQL的scala示例

    简介 spark SQL官网:http://spark.apache.org/docs/latest/sql-programming-guide.html sparkSQL是构建在sparkCore之 ...

  3. Shiro官方快速入门10min例子源码解析框架1-初始化

    Shiro,一个易用的Java安全框架,主要集合身份认证.授权.加密和session管理的功能. 这系文章主要简介Shiro架构,并通过官方的quickstart例程分析最简实现下Shiro的工作流程 ...

  4. HDU 2433 (最短路+BFS+剪枝)

    http://acm.hdu.edu.cn/showproblem.php?pid=2433 这个问题因为路径都是1,所以可以用bfs遍历 可以看这几篇文章讲解: http://blog.csdn.n ...

  5. Java数据库操作(JDBC)

    JDBC Java数据库连接(Java DataBase Connectivity,JDBC)用于在Java程序中实现数据库操作功能,它提供了执行SQL语句.访问各种数据库的方法,并为各种不同的数据库 ...

  6. bsgs(Baby Steps Giant Steps)算法

    BSGS算法(Baby Steps Giant Steps算法,大步小步算法,北上广深算法,拔山盖世算法) 适用问题 对于式子: $$x^y=z(mod_p)$$ 已知x,z,p,p为质数: 求解一个 ...

  7. drupal读取mysql的longblob字段

    unserialize($event->variables)

  8. 转:问题解决:The project cannot be built until build path errors are resolved

    转自:http://blog.csdn.net/marty_zhu/article/details/2566299 今天在eclipse里遇到这个问题,之前也遇到过,不过,通过clean一下项目,或者 ...

  9. PowerDNS Authoritative Server 3.3 发布

    PowerDNS Authoritative Server 3.3 发布,该版本改进了不同验证器的交互操作,修复了不少 bug. PowerDNS Authoritative Server (PDNS ...

  10. win10_64位系统下安装ALM12.01(QC),笔者只在Win10平台上试过,大家也可以在win7的平台上试一下,一个道理!(Alpha)

    HP的ALM是一个非常全面的缺陷管理系统,但安装学习的非常的麻烦,以前学的是ALM,好久没用带今天想学习一下发现安装的非常的困难 !发现网上对ALM的系统安装的介绍非常少,也非常琐碎!今天就借着自己学 ...