【BZOJ 3884】 上帝与集合的正确用法
【题目链接】
【算法】
通过欧拉拓展定理,列出递推公式
【代码】
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; ll T,N;
map<ll,ll> M; template <typename T> inline void read(T &x) {
ll f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
}
template <typename T> inline void writeln(T x) {
write(x);
puts("");
} ll power(ll a,ll n,ll P) {
ll res;
if (n == ) return ;
if (n == ) return a % P;
res = power(a,n>>,P);
res = res * res % P;
if (n & ) res = res * a % P;
return res;
} ll phi(ll x) {
ll i,ret=x;
for (i = ; i <= sqrt(x); i++) {
if (x % i == ) {
while (x % i == ) x /= i;
ret = ret / i * (i - );
}
}
if (x > ) ret = ret / x * (x - );
return ret;
} inline ll calc(ll n) {
if (M.count(n)) return M[n];
return M[n] = power(,calc(phi(n))+phi(n),n);
} int main() { M[] = ;
read(T);
while (T--) {
read(N);
writeln(calc(N));
} return ;
}
【BZOJ 3884】 上帝与集合的正确用法的更多相关文章
- bzoj 3884 上帝与集合的正确用法 指数循环节
3884: 上帝与集合的正确用法 Time Limit: 5 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 根据一些 ...
- BZOJ 3884 上帝与集合的正确用法
Description 根据一些书上的记载,上帝的一次失败的创世经历是这样的: 第一天, 上帝创造了一个世界的基本元素,称做"元". 第二天, 上帝创造了一个新的元素,称作&quo ...
- 【数学】[BZOJ 3884] 上帝与集合的正确用法
Description 根据一些书上的记载,上帝的一次失败的创世经历是这样的: 第一天, 上帝创造了一个世界的基本元素,称做“元”. 第二天, 上帝创造了一个新的元素,称作“α”.“α”被定义为“元” ...
- BZOJ 3884 上帝与集合的正确用法(扩展欧拉定理)
Description 根据一些书上的记载,上帝的一次失败的创世经历是这样的: 第一天, 上帝创造了一个世界的基本元素,称做“元”. 第二天, 上帝创造了一个新的元素,称作“α”.“α”被定义为“ ...
- bzoj 3884 上帝与集合的正确用法(递归,欧拉函数)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3884 [题意] 求2^2^2… mod p [思路] 设p=2^k * q+(1/0) ...
- BZOJ 3884: 上帝与集合的正确用法 [欧拉降幂]
PoPoQQQ大爷太神了 只要用欧拉定理递归下去就好了.... 然而还是有些细节没考虑好: $(P,2) \neq 1$时分解$P=2^k*q$的形式,然后变成$2^k(2^{(2^{2^{...}} ...
- BZOJ.3884.上帝与集合的正确用法(扩展欧拉定理)
\(Description\) 给定p, \(Solution\) 欧拉定理:\(若(a,p)=1\),则\(a^b\equiv a^{b\%\varphi(p)}(mod\ p)\). 扩展欧拉定理 ...
- 解题:BZOJ 3884 上帝与集合的正确用法
题面 好久以前写的,发现自己居然一直没有写题解=.= 扩展欧拉定理:在$b>φ(p)$时有$a^b \equiv a^{b\%φ(p)+φ(p)}(mod$ $p)$ 然后每次递归那个$a^{b ...
- BZOJ 3884: 上帝与集合的正确用法 扩展欧拉定理 + 快速幂
Code: #include<bits/stdc++.h> #define maxn 10000004 #define ll long long using namespace std; ...
- BZOJ 3884 上帝与集合的正确用法题解
一道智慧题 其实解这题需要用到扩展欧拉定理, 有了上面的公式,我们不难看出此题的解法. 设b为2^2^2^2^2.....显然,b要比φ(p)要大,所以可以直接套公式 modp时的答案 ans(p)= ...
随机推荐
- P1536 村村通 洛谷
https://www.luogu.org/problem/show?pid=1536 题目描述 某市调查城镇交通状况,得到现有城镇道路统计表.表中列出了每条道路直接连通的城镇.市政府“村村通工程”的 ...
- systemtap notes
systemtap notes -- 10 June 2014 1 Systemtap systemtap是红帽开发的一款分析工具,如果你需要使用的话,最好在redhat的系统上,在 Ubuntu上兼 ...
- 简单、强大的swig.js
Swig.js A simple, powerful, and extendable JavaScript Template Engine. 简单概括:JS模板引擎. Why to use 根据路劲渲 ...
- POJ 3518 Prime Gap(素数)
POJ 3518 Prime Gap(素数) id=3518">http://poj.org/problem? id=3518 题意: 给你一个数.假设该数是素数就输出0. 否则输出比 ...
- nc和telnet配合使用
nc -l 9932 -c 用nc监听9932端口 telnet 180.150.184.115 29933 telnet 29932 端口
- window.open() 父子页面的传值问题
if(window.opener){//判断是否有父窗口,即打开本页面的窗口 window.opener.location.reload();//刷新父窗口 window.op ...
- v-bind指令
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- centos 安装php7 memcached扩展
在使用下面这种方式安装php7 memcached扩展时,先要安装好memcached服务器yum -y install php70w-pecl-memcached
- JavaScript 的 MVP 框架 Riot.js
Riot.js 详细介绍 Riot.js是一个客户端模型-视图-呈现(MVP)框架并且它非常轻量级甚至小于1kb.尽管他的大小令人难以置信,所有它能构建的有如下:一个模板引擎,路由,甚至是库和一个严格 ...
- Android版DesiredCapabilities参数配置
前言 每一个App测试都应指定是在什么平台下,那个设备中运行那个App,而在Appium中主要是通过DesiredCapabilities来配置的. DesiredCapabilities的作用,负责 ...