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)= ...
随机推荐
- Caused by: java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
需要注意的是ComponentScan 不能扫描 org.springframework 否则会报错,要扫描指定的package才行
- c# + Sql server 事务处理
事务(Transaction)是并发控制的单位,是用户定义的一个操作序列.这些操作要么都做,要么都不做,是一个不可分割的工作单位. 通过事务,SQL Server能将逻辑相关的一组操作绑定在一起,以便 ...
- delphi xe-system.json
Delphi XE10有一个对JSON处理的单元,在你需要使用JSON的单元里面引入"System.json",随后你就可以用Delphi自己的json处理类了. 普通解析 实例1 ...
- 超哥带你学网络编程部分blog
https://www.cnblogs.com/clschao/articles/9593164.html 网络编程 https://www.cnblogs.com/clschao/articles ...
- AutoArchive settings explained
AutoArchive settings explained Applies To: Outlook 2010 More... Less AutoArchive helps manage the sp ...
- showslow / YSlow for PhantomJS/slimerjs(gecko)/phantomas
http://yslow.org/phantomjs/ http://www.bstester.com/2015/12/front-end-performance-using-jenkinsphant ...
- Java算法之“兔子问题”
package wulj; /** * Java算法之“兔子问题”: * 有一只兔子,从出生后第3个月起每个月都生只兔子,小兔子长到第三个月后每个月又生一只兔子,假如兔子都不死,问每个月的兔子总数为多 ...
- Java 语言基础(一)
大多数编程语言都包括以下基本内容: 关键字 标识符 注释 常量和变量 运算符 语句 函数 数组 学习语言最重要的两点: 该语言基础的表现形式是什么 这些东西什么时候使用 关键字 在程序语言中有特殊含义 ...
- Java 面向对象之构造函数和 this 关键字
构造函数 this 关键字 1. 构造函数 class Person { private String name; private int age; // 定义一个 Person 类的构造函数 Per ...
- DRF(5) - 频率组件、url注册器、响应器、分页器
一.频率组件 1.使用DRF简单频率控制实现对用户进行访问频率控制 1)导入模块,定义频率类并继承SimpleRateThrottle # 导入模块 from rest_framework.throt ...