bzoj3884: 上帝与集合的正确用法(数论)
感觉是今天洛谷月赛T3的弱化版,会写洛谷T3之后这题一眼就会写了...
还是欧拉扩展定理
于是就在指数上递归%phi(p)+phi(p)直到1,则后面的指数就都没用了,这时候返回,边回溯边快速幂。因为一个数最多求log次phi就变成1,所以复杂度为O(logp*sqrt(p)),这题线性筛是比直接求要慢的...
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=,inf=1e9;
int T,x;
int p[maxn];
void read(int &k)
{
int f=;k=;char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(c<=''&&c>='')k=k*+c-'',c=getchar();
k*=f;
}
inline int phi(int x)
{
int ans=x;
for(int i=;i*i<=x;i++)
if(!(x%i))
{
ans=ans/i*(i-);
while(!(x%i))x/=i;
}
if(x>)ans=ans/x*(x-);
return ans;
}
inline int power(int a,int b,int mod)
{
if(!a)return ;int ans=;
for(;b;b>>=,a=1ll*a*a%mod)
if(b&)ans=1ll*ans*a%mod;
return ans;
}
int solve(int mod)
{
if(mod==)return ;int tmp;
return power(,solve(tmp=phi(mod))+tmp,mod);
}
int main()
{
read(T);
while(T--)read(x),printf("%d\n",solve(x));
return ;
}
bzoj3884: 上帝与集合的正确用法(数论)的更多相关文章
- bzoj3884上帝与集合的正确用法
Description 根据一些书上的记载,上帝的一次失败的创世经历是这样的: 第一天, 上帝创造了一个世界的基本元素,称做“元”. 第二天, 上帝创造了一个新的元素,称作“α”.“α”被定义为“ ...
- BZOJ3884: 上帝与集合的正确用法 拓展欧拉定理
Description 根据一些书上的记载,上帝的一次失败的创世经历是这样的: 第一天, 上帝创造了一个世界的基本元素,称做“元”. 第二天, 上帝创造了一个新的元素,称作“α”.“α”被定义为“ ...
- BZOJ3884: 上帝与集合的正确用法(欧拉函数 扩展欧拉定理)
Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 3860 Solved: 1751[Submit][Status][Discuss] Descripti ...
- 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 ...
- bzoj3884: 上帝与集合的正确用法 扩展欧拉定理
题意:求\(2^{2^{2^{2^{...}}}}\%p\) 题解:可以发现用扩展欧拉定理不需要很多次就能使模数变成1,后面的就不用算了 \(a^b\%c=a^{b\%\phi c} gcd(b,c) ...
- bzoj千题计划264:bzoj3884: 上帝与集合的正确用法
http://www.lydsy.com/JudgeOnline/problem.php?id=3884 欧拉降幂公式 #include<cmath> #include<cstdio ...
- BZOJ3884 上帝与集合的正确用法(欧拉函数)
设f(n)为模n时的答案,由2k mod n=2k mod φ(n)+φ(n) mod n(并不会证),且k mod φ(n)=f(φ(n)),直接就可以得到一个递推式子.记搜一发即可. #inclu ...
- [bzoj3884]上帝与集合的正确用法——欧拉函数
题目大意 题解 出题人博客 代码 #include <bits/stdc++.h> using namespace std; const int M = 10001000; int phi ...
随机推荐
- PHASER3 设置场景SCENE SLEEPING休眠和WAKE唤醒
A good way to set scene stop when hidden and run while visible again ! 使用sleep和wake方法的好处: 1.可以彻底让sce ...
- 测试类异常Manual close is not allowed over a Spring managed SqlSession
在用Spring 和mybatis整合的 写测试类的时候报出解决办法:在全局配置文件 class="org.mybatis.spring.SqlSessionTemplate" ...
- Dilworth定理
来自网络的解释: 定理内容及其证明过程数学不好看不懂. 通俗解释: 把一个数列划分成最少的最长不升子序列的数目就等于这个数列的最长上升子序列的长度(LIS) EXAMPLE 1 HDU 1257 ...
- NodeJS实现同步的方法
NodeJS被打上了单线程.非阻塞.事件驱动…..等标签. 在单线程的情况下,是无法开启子线程的.经过了很久的研究,发现并没有thread函数!!!但是有时候,我们确实需要“多线程”处理事务.node ...
- gopherjs
An example implementation of a GopherJS client and a Go server using the Improbable gRPC-Web impleme ...
- PowerDesigne 建立概念数据模型
本文主要介绍PowerDesigner概念数据模型以及实体.属性创建. 一.新建概念数据模型1)选择File-->New,弹出如图所示对话框,选择CDM模型(即概念数据模型)建立模型. 2)完成 ...
- LeetCode 888. Fair Candy Swap(C++)
题目: Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy that ...
- FivePlus——团队展示
光耀101 <光耀101>是福州大学数计学院计算机专业推出的中国首部程序猿脱发养成节目.由张栋担任发起人,刘晨瑶.畅畅担任导师. 该节目召集了你猜多少位选手,通过任务.训练.考核,让选 ...
- 静默调用ShellContextMenu 实现QQ文件共享
我在CSDN提问题一直没人回复,一下午时间自己终于解决了问题 http://bbs.csdn.net/topics/391916381 现将过程录下 先说需求,我想实现的功能是 在程序中对文件调用百度 ...
- 期中HTML代码及技术博客
<!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...