同: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. D. Make a Permutation!(思维)

    D. Make a Permutation! time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. [BZOJ2208]:[Jsoi2010]连通数(暴力 or bitset or 塔尖?)

    题目传送门 题目描述 度量一个有向图连通情况的一个指标是连通数,指图中可达顶点对的个数. 在上图中,顶点1可以到达1.2.3.4.5. 顶点2可以到达2.3.4.5. 顶点3可以到达3.4.5. 顶点 ...

  3. [题解] [CF451E] Devu and Flowers

    题面 题解 就是一个求\(\sum_{i= 1}^{n}x _ i = m\)的不重复多重集的个数, 我们可以由容斥原理得到: \[ ans = C_{n + m - 1}^{n - 1} - \su ...

  4. sql把一段时间分割成周,月,季度,年的时间段

    --本周 select TO_CHAR(CREATE_DATE ,'yyyy-MM-dd')as NEW_DATE , TO_CHAR(trunc(CREATE_DATE, ,'yyyy-MM-dd' ...

  5. __new()__与__init__()

    1. __new__:创建对象时调用,会返回当前对象的一个实例.(默认情况下也就是你在类中没有没有重新这个方法,会默认返回当前类的示例,如果你重写了这个方法,但是在方法中没有返回当前类的示例,那么也就 ...

  6. Zookeeper执行原理的详细概述

    文章作者:Holy Null,来源:http://holynull.leanote.com/post/Zookeeper,非常感谢作者提供如此优秀的原创文章,作者通过俩个月的努力将<Hadoop ...

  7. Nginx-rtmp直播之业务流程分析

    1. 综述 1.1 直播原理 使用 obs 向 nginx 推送一个直播流,该直播流经 nginx-rtmp 的 ngx_rtmp_live_module 模块转发给 application live ...

  8. numpy之填充为nan的数据为该列平均值

    # coding=utf-8 import numpy as np ''' 填充nan的数据,为该列的平均值 ''' def fill_ndarray(t1): for i in range(t1.s ...

  9. 在smarty模板中截取指定长度的字符串

    在smarty模板中截取指定长度的字符串,可使用truncate这个插件. 用法: {{$data.value|truncate:28:'...'}} 28个字节14个字数输出,多余部分输出...,一 ...

  10. shutil使用

    1.用shutil移动文件, import shutil shutil.move('/root/test.yaml','/home/') shutil.move('/root/k8s.py','/ho ...