bzoj3884: 上帝与集合的正确用法 欧拉降幂公式
2016-07-22 21:28
281 查看
欧拉降幂公式:http://blog.csdn.net/acdreamers/article/details/8236942
糖教题解处:http://blog.csdn.net/skywalkert/article/details/43955611
注:知道欧拉公式是远远不够的,还要知道欧拉降幂公式,因为当指数很大的时候需要用
然后欧拉降幂公式不要求A,C互质,但是B必须大于等于C的欧拉函数
吐槽:感觉记忆化搜索影响不大啊,当然肯定是因为太水了
这样复杂度是O(T*sqrt(p)*logp)
#include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <vector> #include <math.h> #include <stack> #include <map> using namespace std; typedef long long LL; const int N = 11; int qpow(int a,int b,int mod){ int ret=1; while(b){ if(b&1)ret=1ll*ret*a%mod; a=1ll*a*a%mod; b>>=1; } return ret; } int eular(int x){ int ret=x; for(int i=2;i*i<=x;++i){ if(x%i)continue; ret=ret/i*(i-1); while(x%i==0)x/=i; } if(x>1)ret=ret/x*(x-1); return ret; } int f(int x){ if(x==1)return 0; int phi=eular(x); return qpow(2,f(phi)+phi,x); } int main(){ int T; scanf("%d",&T); while(T--){ int p; scanf("%d",&p); printf("%d\n",f(p)); } return 0; }
View Code
相关文章推荐
- MySQL C API
- Codeforces Round #363 (Div. 2) C. Vacations
- Biee 迁移和刷新GUIDs
- C语言中的单引号和双引号的区别
- margin之百分比
- HDOJ 2018 母牛的故事
- 大数据spark蘑菇云行动前传第5课:零基础彻底实战Scala函数式编程及Spark源码解析
- 常用算法思想之:递归思想
- linux基础入门
- ubuntu 用root登陆图形界面
- Codeforces 468B Two Sets(超直白解释)
- CodeForces 489B BerSU Ball (贪心)
- UVALive 2756 Crazy tea party
- 初探Python(1)
- 线段香蕉
- Doing Homework again (贪心)
- 实验项目3-5:求链表线性表的倒数第K项
- 思路:如何跳过CreateProcess调用底层创建进程函数
- table头部、尾部固定;中间内容定高自适应滚动
- linux笔记十----虚拟机网络配置