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)= ...
随机推荐
- Get请求-Test版
package com.fanqi.test; import java.io.DataInputStream; import java.io.IOException; import java.io.I ...
- fineReport---sql
一.开窗函数-逐层平均 在创建数据集时用sql的开窗排名函数[AVG(字段) over(PARTITION BY 分组字段 order by 逐层字段)]处理,然后进行直接调用. 详细说明 二.开窗函 ...
- 科学计算 NumPy 与C语言对比 N-dimensional array ndarray 元素元素操作 计算正太分布分位数
w http://www.numpy.org/ NumPy is the fundamental package for scientific computing with Python. It co ...
- <2014 08 29> MATLAB的软件结构与模块、工具箱简示
MATLAB的系统结构:三个层次.九个部分 ----------------------------------- 一.基础层 是整个系统的基础,核心内容是MATLAB部分. 1.软件主包MATLAB ...
- 常用的SQLAlchemy列选项
常用的SQLAlchemy列选项 https://blog.csdn.net/weixin_41896508/article/details/80772238 选项名 说明 primary_key 如 ...
- Java基础语法 - 面向对象 - 类的主方法main方法
主方法是类的入口点,它指定了程序从何处开始,提供对程序流向的控制.Java编译器通过主方法来执行程序. 主方法的语法如下: /* a.主方法是静态的,如果要直接在主方法中调用其它方法,则该方法必须也是 ...
- 模块 - time/datetime
time 模块 time模块方法: >>> import time >>> time.time() #时间戳 秒级别 1519212085.6211221 #从19 ...
- 从一个git仓库迁移到另外一个git仓库
1 从原地址克隆一份裸版本库,比如原本托管于 GitHub. git clone --bare git://github.com/username/project.git git操作的结果会有一个XX ...
- celery中的生产者消费者问题
celery中的生产者消费者问题 在task1.py文件中: # demo1:task.py and celery.py in one file# run it byfrom celery impor ...
- MySQL之表的约束
一 介绍 约束条件与数据类型的宽度一样,都是可选参数 作用:用于保证数据的完整性和一致性主要分为: PRIMARY KEY (PK) 标识该字段为该表的主键,可以唯一的标识记录 FOREIGN KEY ...