bzoj 3884 上帝与集合的正确用法 指数循环节
3884: 上帝与集合的正确用法
Time Limit: 5 Sec Memory Limit: 128 MB
[Submit][Status][Discuss]
Description

Input
Output
Sample Input
2
3
6
Sample Output
1
4
HINT
我的思路:因为无限次数,所以次方一定大于模;指数循环节;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+,M=1e6+,mod=1e9+,inf=1e9+;
ll phi(ll n)
{
ll i,rea=n;
for(i=;i*i<=n;i++)
{
if(n%i==)
{
rea=rea-rea/i;
while(n%i==) n/=i;
}
}
if(n>)
rea=rea-rea/n;
return rea;
}
ll quickpow(ll x,ll y,ll z)
{
ll ans=;
while(y)
{
if(y&)
ans*=x,ans%=z;
x*=x;
x%=z;
y>>=;
}
return ans;
}
ll solve(ll k,ll mod)
{
if(mod==) return ;
ll tmp=phi(mod);
ll up=solve(k,tmp);
ll ans=quickpow(k,up+tmp,mod);
return ans;
}
int main()
{
ll x,p,i,t;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld",&p);
printf("%lld\n",solve(2ll,p)%p);
}
return ;
}
popoqqq:http://blog.csdn.net/popoqqq/article/details/43951401
int solve(int p)
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iterator>
#include<stack>
using namespace std;
const int INF=1e9+;
const double eps=1e-;
const int N=1e7+;
const int M=;
typedef long long ll;
ll phi(ll n)
{
ll i,rea=n;
for(i=;i*i<=n;i++)
{
if(n%i==)
{
rea=rea-rea/i;
while(n%i==) n/=i;
}
}
if(n>)
rea=rea-rea/n;
return rea;
}
ll Pow(ll a,ll n,ll mod)
{
ll ans=;
while(n)
{
if(n&)
{
ans=ans*a%mod;
}
a=a*a%mod;
n>>=;
}
if(ans==) ans+=mod;
return ans;
}
ll solve(ll k,ll mod)
{
if(mod==) return mod;
ll tmp=phi(mod);
ll up=solve(k,tmp);
ll ans=Pow(k,up,mod);
return ans;
}
int main()
{
ll n,m,p;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld",&p);
ll ans=solve(2ll,p);
printf("%lld\n",ans%p);
}
return ;
}
bzoj 3884 上帝与集合的正确用法 指数循环节的更多相关文章
- 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)= ...
随机推荐
- jpa关联映射
参考:http://www.cnblogs.com/printN/p/6408818.html 官方文档:http://docs.jboss.org/hibernate/orm/5.2/usergui ...
- cocos2d-X学习之主要类介绍:场景(CCScene)
场景(CCScene) 类结构: CCScene主要有以下两个函数: bool init () //初始化函数 static CCScene * node (void) //生CCScene 作为 ...
- MySQL5.7安装及遇到的问题
Mysql安装教程: mysql历史版本下载 将在官网下载的安装包解压(如:如D:\mysql-5.7.19-x64) 1.(修复问题Q1时必做,全新安装时不要删除)在mysql的安装路径(如D:\ ...
- What is Grammar?
What is Grammar? And why grammar is your friend… Grammar(noun): the structure and system of a langua ...
- 创建存储过程修改role密码
1 创建存储过程 DELIMITER | drop procedure if exists pro_update_role_pwd; CREATE PROCEDURE pro_update_role_ ...
- .net 存储过程中的 output参数取值问题
当存储过程中多个结果需要返回时经常需要用到output类型的参数,如果存储过程没有返回结果集只是输出output类型参数时使用如下代码: db.AddOutParameter(dbCmd, " ...
- Python高级教程-列表生成式
List Comprehensions(列表生成式) 列表生成式,是Python内置的非常简单却强大的可以用来创建list的生成式. 例如,要生成list:[1,2,3,4,5,6,7,8,9,10] ...
- Ubuntu学习笔记3-图书知识点总结
免费的虚拟机软件:vmware server Ubuntu下切换到root用户: 1,su 2, sudo -s 3, sudo+命令 Ubuntu下切换到一般用户: su chennan 软件包的安 ...
- 移动端笔记——jQuery touch事件
判断移动端还是pc端 function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = new Array("A ...
- eclipse添加tomcat运行时
方法一:添加jar包 方法二配置依赖 比如缺少javax.servlet.http.HttpServlet,ctrol+shift+t查找这个包 <dependencies> <de ...