同: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. sh_13_字典的应用场景

    sh_13_字典的应用场景 # 使用 多个键值对,存储 描述一个 物体 的相关信息 —— 描述更复杂的数据信息 # 将 多个字典 放在 一个列表 中,再进行遍历 card_list = [ {&quo ...

  2. less命令:查看文件内容

    less 命令的作用和 more 十分类似,都用来浏览文本文件中的内容,不同之处在于,使用 more 命令浏览文件内容时,只能不断向后翻看,而使用 less 命令浏览,既可以向后翻看,也可以向前翻看. ...

  3. ssh链接取消密码

    进入到存放秘钥的文件夹,输入 ssh-add id_rsa 然后输入两次密码即可.

  4. CodeForces–833B--The Bakery(线段树&&DP)

    B. The Bakery time limit per test 2.5 seconds memory limit per test 256 megabytes input standard inp ...

  5. 在Spring Boot快捷地读取文件内容的若干种方式

    引言: 在Spring Boot构建的项目中,在某些情况下,需要自行去读取项目中的某些文件内容,那该如何以一种轻快简单的方式读取文件内容呢?  基于ApplicationContext读取 在Spri ...

  6. ILSpy C# language support status

    C# language support status Asynchronous methods 已经支持 Generalized async return types  还不支持 Async main ...

  7. leetcode-hard-array-41. First Missing Positive-NO

    mycode class Solution(object): def firstMissingPositive(self, nums): """ :type nums: ...

  8. [转]zookeeper入门

    zookeeper的目标是将复杂且容易出错的分布式一致性服务封装起来,构成一个高效可靠的原语集,并以一系列简单易用的接口提供给用户使用. 参考文章:http://developer.51cto.com ...

  9. LC 711. Number of Distinct Islands II

    Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...

  10. 2019-8-13未命名文件 sdfsdfsdfsdfsdfsdf

    2019-8-13未命名文件 sdfsdfsdfsdfsdfsdf 新建模板小书匠 欢迎使用 小书匠(xiaoshujiang)编辑器,您可以通过 小书匠主按钮>模板 里的模板管理来改变新建文章 ...