同:https://www.cnblogs.com/--HPY-7m/p/11444923.html

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<ll, vector<ll>, greater<ll> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register ll a=b;a<=c;++a)
#define fr(a,b,c) for(register ll a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
void swapp(ll &a,ll &b);
double fabss(double a);
ll maxx(ll a,ll b);
ll minn(ll a,ll b);
ll Del_bit_1(ll n);
ll lowbit(ll n);
ll abss(ll a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const ll inf=(<<);
const double ESP=1e-;
//const ll mod=(ll)1e9+7;
const ll N=(ll)1e6+; ll n__;
map<ll,ll>mp;
long long phi(long long n)//a^(b mod phi(c)+phi(c)) mod c
{
if(mp.count(n))return mp[n];//记忆化;
long long i,rea=n,temp=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;
mp[temp]=rea;
return rea;
}
ll Mod(ll x, ll m)
{
return x>=m?x%m+m:x;
}
long long qpow(long long a,long long b,long long mod)
{
long long ans,fl=;
// ll ta=a,tb=b,tta=a;
ans=;
while(b!=)
{
if(b&)
{
if(ans*a>=mod)fl=;
ans=ans*a%mod;
}
b/=;
if(!b)break;
if(a*a>=mod)fl=;
a=a*a%mod;
}
return ans+(fl?mod:);
}
ll solve(ll l,ll r,ll mod)//返回l~r计算结果; 听说phi(phi(mod))~==~mod/2所有最多log次;
{
if(l==r||mod==)return Mod(n__,mod);//任何数%1都是0,不用再算了;
return qpow(n__,solve(l+,r,phi(mod)),mod);//假设我已经知道了l+1~r的结果:递归下去;
} int main()
{
ll T;
sc("%lld",&T);
while(T--)
{
ll cnt;
ll p;
sc("%lld%lld%lld",&n__,&cnt,&p);
if(cnt==) printf("%lld\n",(ll)(%p));
else pr("%lld\n",solve(,cnt,p)%p);
}
return ;
} /**************************************************************************************/ ll maxx(ll a,ll b)
{
return a>b?a:b;
} void swapp(ll &a,ll &b)
{
a^=b^=a^=b;
} ll lowbit(ll n)
{
return n&(-n);
} ll Del_bit_1(ll n)
{
return n&(n-);
} ll abss(ll a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} ll minn(ll a,ll b)
{
return a<b?a:b;
}

B.super_log(The Preliminary Contest for ICPC Asia Nanjing 2019)的更多相关文章

  1. H.Holy Grail ( floyd )(The Preliminary Contest for ICPC Asia Nanjing 2019)

    题意: 给出一个有向图,再给出6条原来不存在的路径,让你在这6条路径上添加一个最小的数,使图不存在负环. 思路: 直接6遍 floyd 输出就行了. #include <bits/stdc++. ...

  2. F. Greedy Sequence(主席树区间k的后继)(The Preliminary Contest for ICPC Asia Nanjing 2019)

    题意: 查找区间k的后继. 思路: 直接主席树. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio&g ...

  3. G.Colorful String(The Preliminary Contest for ICPC Asia Xuzhou 2019)

    https://nanti.jisuanke.com/t/4 #include <bits/stdc++.h> using namespace std; ,; typedef unsign ...

  4. E.XKC's basketball team(The Preliminary Contest for ICPC Asia Xuzhou 2019)

    https://nanti.jisuanke.com/t/41387 解: 离散化+线段树. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); ...

  5. A.Who is better?(The Preliminary Contest for ICPC Asia Xuzhou 2019)

    https://nanti.jisuanke.com/t/41383 解: 斐波那契博弈+中国剩余定理. #include <bits/stdc++.h> using namespace ...

  6. The Preliminary Contest for ICPC Asia Nanjing 2019 D. Robots

    题意:给出一个DAG,一只机器人从1点出发,等概率地选择一条出边走或者停留在原点,机器人的第k次行动消耗能量是k(无论是走还是停留都算一次行动).问1到n的期望. 解法:因为行动消耗的能量跟行动次数有 ...

  7. The Preliminary Contest for ICPC Asia Nanjing 2019 B. super_log (广义欧拉降幂)

    In Complexity theory, some functions are nearly O(1)O(1), but it is greater then O(1)O(1). For examp ...

  8. The Preliminary Contest for ICPC Asia Nanjing 2019( B H F)

    B. super_log 题意:研究一下就是求幂塔函数 %m的值. 思路:扩展欧拉降幂. AC代码: #include<bits/stdc++.h> using namespace std ...

  9. [The Preliminary Contest for ICPC Asia Nanjing 2019] A-The beautiful values of the palace(二维偏序+思维)

    >传送门< 前言 这题比赛的时候觉得能做,硬是怼了一个半小时,最后还是放弃了.开始想到用二维前缀和,结果$n\leq 10^{6}$时间和空间上都爆了,没有办法.赛后看题解用树状数组,一看 ...

随机推荐

  1. Java集合框架中底层文档的List与Set

    Java集合框架中的List与Set // 简书作者:达叔小生 Collection -> Set 无序不重复 -> 无序HashSet,需要排序TreeSet -> List 有序 ...

  2. 记使用vim常用的快捷键

    显示行数  :set nu 跳转到最后一行 G 跳转到指定行数 nG  n为行数 跳转到行首 0 跳转到行尾 $ (shift+4)

  3. BZOJ 5330 Luogu P4607 [SDOI2018]反回文串 (莫比乌斯反演、Pollard Rho算法)

    题目链接 (BZOJ) https://www.lydsy.com/JudgeOnline/problem.php?id=5330 (Luogu) https://www.luogu.org/prob ...

  4. 大体知道java语法2----------理解面向对象

    我参加过大大小小n场面试,被好几位面试官问到过:能不能谈谈面向对象的几大特征?什么是面向对象?对于这两个问题,我始终觉得一定要理解,其实不只是这种概念题(姑且算它是概念题吧),包括各种语法都应该去理解 ...

  5. shiro 不使用加密 解决 org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token [org.apache.sh

    测试本方法为失效的 报错: org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token ...

  6. TCP最大报文段MSS源码分析

    概述 本文主要对MSS相关的几个字段结合源码流程进行分析: 字段含义 user_mss(tcp_options_received)–用户配置的mss,优先级最高: mss_clamp(tcp_opti ...

  7. 修改mp3图片和信息——BesMp3Editor

    导读 BesMp3Editor, 是一款小巧的 MP3 编辑工具,可以修改.添加 MP3 上的图片.歌曲名.歌手.专辑信息. 最近想给 BesLyric-for-X 添加一个功能,为下载下来的歌曲添加 ...

  8. koa 基础(二十一)nodejs 操作mongodb数据库 --- 查询数据

    1.app.js /** * nodejs 操作mongodb数据库 * 1.安装 操作mongodb * cnpm install mongodb --save * 2.引入 mongodb 下面的 ...

  9. android data binding jetpack II 动态数据更新

    android data binding jetpack VIII BindingConversion android data binding jetpack VII @BindingAdapter ...

  10. oracle中删除某个用户下的所有表

    一般的方法:先使用sql查询: SELECT 'DELETE FROM '|| table_name || ';' FROM USER_TABLES ORDER BY TABLE_NAME; 将查询结 ...