BZOJ3884 上帝与集合的正确用法 【欧拉定理】
题目

对于100%的数据,T<=1000,p<=10^7
题解
来捉这道神题
欧拉定理的一般形式:
\]
我们令
\]
那么有
\]
\(O(\log p)\)递归即可
#include<iostream>
#include<cstdio>
#include<cmath>
#include<bitset>
#include<cstring>
#include<algorithm>
#define LL long long int
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define BUG(s,n) for (int i = 1; i <= (n); i++) cout<<s[i]<<' '; puts("");
using namespace std;
const int maxn = 10000005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
bitset<maxn> isn;
int p[maxn],phi[maxn],pi;
void init(){
phi[1] = 1;
for (int i = 2; i <= 10000000; i++){
if (!isn[i]) p[++pi] = i,phi[i] = i - 1;
for (int j = 1; j <= pi && i * p[j] <= 10000000; j++){
isn[i * p[j]] = true;
if (i % p[j] == 0){
phi[i * p[j]] = phi[i] * p[j];
break;
}
phi[i * p[j]] = phi[i] * (p[j] - 1);
}
}
}
int qpow(int a,int b,int p){
int ans = 1;
for (; b; b >>= 1,a = 1ll * a * a % p)
if (b & 1) ans = 1ll * ans * a % p;
return ans;
}
int Ans(int p){
if (p == 1) return 0;
return qpow(2,Ans(phi[p]) + phi[p],p);
}
int main(){
init();
int T = read(),p;
while (T--){
p = read();
printf("%d\n",Ans(p));
}
return 0;
}
BZOJ3884 上帝与集合的正确用法 【欧拉定理】的更多相关文章
- 【BZOJ3884】上帝与集合的正确用法 [欧拉定理]
上帝与集合的正确用法 Time Limit: 5 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description Input 第一行一个T ...
- BZOJ3884: 上帝与集合的正确用法 拓展欧拉定理
Description 根据一些书上的记载,上帝的一次失败的创世经历是这样的: 第一天, 上帝创造了一个世界的基本元素,称做“元”. 第二天, 上帝创造了一个新的元素,称作“α”.“α”被定义为“ ...
- BZOJ3884: 上帝与集合的正确用法(欧拉函数 扩展欧拉定理)
Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 3860 Solved: 1751[Submit][Status][Discuss] Descripti ...
- bzoj3884: 上帝与集合的正确用法 扩展欧拉定理
题意:求\(2^{2^{2^{2^{...}}}}\%p\) 题解:可以发现用扩展欧拉定理不需要很多次就能使模数变成1,后面的就不用算了 \(a^b\%c=a^{b\%\phi c} gcd(b,c) ...
- bzoj3884上帝与集合的正确用法
Description 根据一些书上的记载,上帝的一次失败的创世经历是这样的: 第一天, 上帝创造了一个世界的基本元素,称做“元”. 第二天, 上帝创造了一个新的元素,称作“α”.“α”被定义为“ ...
- [BZOJ3884] 上帝与集合的正确用法 (欧拉函数)
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3884 题目大意: 给出 M, 求 $2^{2^{2^{2^{...}}}}$ % M ...
- bzoj3884 上帝与集合的正确用法
a^b mod P=a^(b mod phi(p)) mod p,利用欧拉公式递归做下去. 代码 #pragma comment(linker,"/STACK:1024000000,1024 ...
- bzoj3884: 上帝与集合的正确用法 欧拉降幂公式
欧拉降幂公式:http://blog.csdn.net/acdreamers/article/details/8236942 糖教题解处:http://blog.csdn.net/skywalkert ...
- bzoj千题计划264:bzoj3884: 上帝与集合的正确用法
http://www.lydsy.com/JudgeOnline/problem.php?id=3884 欧拉降幂公式 #include<cmath> #include<cstdio ...
随机推荐
- subline 安装 package control
subline text2 输入 import urllib2,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa154 ...
- org.hibernate.hql.internal.ast.QuerysyntaxException:user is not mapped [from User where user_code=? and user_password=?]
初学者,一个很低级的错误吧! 找不到映射,最后发现没把类的Hibernate映射文件 添加到Hibernate核心配置文件中去,所以报了这个异常! 在核心文件中添加映射 <mapping r ...
- EasyUI取消树节点选中
$('#organTree').find('.tree-node-selected').removeClass('tree-node-selected'); 取消树的节点选中
- 6- vue django restful framework 打造生鲜超市 -完成商品列表页(下)
Vue+Django REST framework实战 搭建一个前后端分离的生鲜超市网站 Django rtf 完成 商品列表页下 drf中的request和response drf对于django的 ...
- vue-cli的build的文件夹下没有dev-server.js文件,怎么配置mock数据
因为最新版本的vue-cli已经放弃dev-server.js,只需在webpack.dev.conf.js配置就行 新版webpack.dev.conf.js配置如下: 在const portfin ...
- shell的条件判断
.字符串判断 str1 = str2 当两个串有相同内容.长度时为真 str1 != str2 当串str1和str2不等时为真 -n str1 当串的长度大于0时为真(串非空) -z str1 当串 ...
- 原生node实现本地静态页面的展示
var http = require("http"); var fs = require("fs"); var url = require("url& ...
- tcl之基本语法—1
- Android四大基本组件介绍及生命周期
Android四大基本组件分别是Activity,Service服务,Content Provider内容提供者,BroadcastReceiver广播接收器. 一.了解四大基本组件 Activity ...
- 千万不要错过这几道Python面试题,Python面试题No16
第1题: python下多线程的限制以及多进程中传递参数的方式? python多线程有个全局解释器锁(global interpreter lock),简称GIL,这个GIL并不是python的特性, ...