B.super_log(The Preliminary Contest for ICPC Asia Nanjing 2019)
同: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)的更多相关文章
- H.Holy Grail ( floyd )(The Preliminary Contest for ICPC Asia Nanjing 2019)
题意: 给出一个有向图,再给出6条原来不存在的路径,让你在这6条路径上添加一个最小的数,使图不存在负环. 思路: 直接6遍 floyd 输出就行了. #include <bits/stdc++. ...
- 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 ...
- 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 ...
- 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); ...
- A.Who is better?(The Preliminary Contest for ICPC Asia Xuzhou 2019)
https://nanti.jisuanke.com/t/41383 解: 斐波那契博弈+中国剩余定理. #include <bits/stdc++.h> using namespace ...
- The Preliminary Contest for ICPC Asia Nanjing 2019 D. Robots
题意:给出一个DAG,一只机器人从1点出发,等概率地选择一条出边走或者停留在原点,机器人的第k次行动消耗能量是k(无论是走还是停留都算一次行动).问1到n的期望. 解法:因为行动消耗的能量跟行动次数有 ...
- 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 ...
- The Preliminary Contest for ICPC Asia Nanjing 2019( B H F)
B. super_log 题意:研究一下就是求幂塔函数 %m的值. 思路:扩展欧拉降幂. AC代码: #include<bits/stdc++.h> using namespace std ...
- [The Preliminary Contest for ICPC Asia Nanjing 2019] A-The beautiful values of the palace(二维偏序+思维)
>传送门< 前言 这题比赛的时候觉得能做,硬是怼了一个半小时,最后还是放弃了.开始想到用二维前缀和,结果$n\leq 10^{6}$时间和空间上都爆了,没有办法.赛后看题解用树状数组,一看 ...
随机推荐
- Spring——5种增强方式
一.前置增强 二.后置增强 三.环绕增强 环绕增强相当于前置增强和后置增强的结合体,可以使用<aop:around>进行处理,这里我采用代理工厂的方式 1.接口及其实现类 public ...
- Cortex-M3 入门指南(三):时钟总线与复位时钟控制器
[reset clock control 复位和时钟控制器] 时钟信号对于处理器非常重要,比如我们熟悉的 CPU 就是由时钟信号驱动的,而主频就是内核的的时钟信号频率.Cortex-M3 有着复杂的 ...
- MySQL_(Java)使用JDBC向数据库中删除(delete)数据
MySQL_(Java)使用JDBC向数据库发起查询请求 传送门 MySQL_(Java)使用JDBC向数据库中插入(insert)数据 传送门 MySQL_(Java)使用JDBC向数据库中删除(d ...
- [题解] [AtCoder2134] Zigzag MST
题面 题解 考虑kruscal的过程 对于三个点\(x, y, x + 1\), 我们可以将\((x, y, z), (y, x + 1, z + 1)\)看做\((x, y, z), (x, x + ...
- iPhone/iPad调整事件递交
UIKit 为应用程序提供了编程手段来简化事件处理或者完全关闭事件流.下面的列表总结了这些方法: 关闭触摸事件的递交. 缺省情况下,视图接收触摸事件,但是你可以设置它的userInteractionE ...
- vue 2.x 的 v-bind 指令的 .prop 事件修饰符详解
vue 官方文档对 .prop 修饰符的解释是: 使用例子: 那么,具体的原理和用法是什么呢?这要从 html 的 DOM node 说起. 在 html 标签里,我们可以定义各种 attribute ...
- IDEA如何配置jdk路径
首先要确定你的jdk已经安装好了 Win + R键,输入cmd 输入java -version 当返回这玩意的时候,就证明你的jdk已经安装成功,可以用IDEA进行配置了 打开IDEA的 File → ...
- TCP滑动窗口Sliding Window
滑动窗口的发送窗口示意图如下,其中由对端通告的窗口窗口大小为6,窗口中和窗口外的数据分别表示为:1-3发送并已经被确认的数据段,4-6发送但尚未被确认的数据段,7-9能够发送尚未发送的数据段,10-… ...
- mysql统计前24小时数据没有补0
SELECT t1. HOUR HOUR, COUNT(t2. HOUR) count FROM ( SELECT DATE_FORMAT( HOUR), '%y-%m-%d %H' ) HOUR F ...
- Visual Studio Code 编辑器使用
image.png 之前一直都是用 sublime text 作为开发工具,用久了自然而然会觉得生活无趣,而且当时用sublime text 装了很多插件,有些插件不能用,于是决定试试微软的新产品 ...