codeforces 17D Notepad

题意

题解

TBD

更新模板(phi、欧拉降幂)

代码

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(x) (int)x.size()
#define de(x) cout<< #x<<" = "<<x<<endl
#define dd(x) cout<< #x<<" = "<<x<<" "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi; string B, N;
ll c, b, n; ll add(ll a, ll b, int P) {
return (a + b) % P;
}
ll mul(ll a, ll b, int P) {
return a * b % P;
}
ll calc(string s, int P) {
ll res = 0;
rep(i, 0, sz(s)) res = add(mul(res, 10, P), s[i] - '0', P);
return res;
}
int phi(int n) {
int ans=n;
for(int i=2;i*i<=n;i++) if(n%i==0) {
ans=ans/i*(i-1);
while(n%i==0)n/=i;
}
if(n>1)ans=ans/n*(n-1);
return ans;
}
ll kpow(ll a, ll b, int P) {
ll res = 1;
while(b) {
if(b & 1) res = mul(res, a, P);
a = mul(a, a, P);
b >>= 1;
}
return res;
} int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin >> B >> N >> c;
int pc = phi(c);
b = calc(B, c);
n = calc(N, pc);
n = add(n, pc - 1, pc);
ll ans;
if(sz(N) < 11) {
ll x = 0;
rep(i, 0, sz(N)) x = x * 10 + N[i] - '0';
ans = kpow(b, x - 1, c);
} else {
ans = kpow(b, n + pc, c);
}
b = add(b, c - 1, c);
ans = mul(ans, b, c);
cout << (ans ? ans : c) << endl;
return 0;
}

codeforces 17D Notepad的更多相关文章

  1. CodeForces 17D Notepad(同余定理)

    D. Notepad time limit per test 2 seconds memory limit per test 64 megabytes input standard input out ...

  2. Codeforces 17D Notepad 简单的数论

    从题意,anw =  (b-1)*b^(n-1)%c,强调,为了b^(n-1). 弱渣只能推了宣传. phi(c)为小于c且与c互质的个数. 当x >= phi(c)时:A^x = A(x%ph ...

  3. Codeforces Beta Round #17 D.Notepad 指数循环节

    D. Notepad time limit per test 2 seconds memory limit per test 64 megabytes input standard input out ...

  4. Codeforces Beta Round #17 D. Notepad (数论 + 广义欧拉定理降幂)

    Codeforces Beta Round #17 题目链接:点击我打开题目链接 大概题意: 给你 \(b\),\(n\),\(c\). 让你求:\((b)^{n-1}*(b-1)\%c\). \(2 ...

  5. Codeforces 1672 E. notepad.exe

    题意 这是一道交互题,有n个字符串,每个字符串长度:0-2000, n :0-2000 有一个机器对他进行排版,你可以给他一个每行的最大宽度w,那么每行只能放长度为w的字符: 每行相邻两个字符串之间至 ...

  6. Codeforces Round #274 (Div. 1) C. Riding in a Lift 前缀和优化dp

    C. Riding in a Lift Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/pr ...

  7. Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】

    A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  8. Codeforces 833A The Meaningless Game - 数论 - 牛顿迭代法 - 二分法

    Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. T ...

  9. Codeforces Round #426 The Meaningless Game

    题目网址:http://codeforces.com/contest/834/problem/C 题目: C. The Meaningless Game Slastyona and her loyal ...

随机推荐

  1. Hive学习之Locking

    众所周知,数据库必须要能够支持并发.无论在任何时候,允许同一时刻,多个用户能够同时读取或写入.没有必要给用户提供API显示的获取锁,所以所有的锁都是隐式获取的. 在Hive中有两种类型的锁: 共享锁S ...

  2. clientX/Y pageX/Y offsetX/Y layerX/Y screenX/Y clientHeight innerWidth...

    关于js鼠标事件综合各大浏览器能获取到坐标的属性总共以下五种 event.clientX/Y event.pageX/Y event.offsetX/Y event.layerX/Y event.sc ...

  3. [Codeforces 932E]Team Work

    Description 题库链接 求 \[\sum_{i=1}^n C(n,i)\times i^k\] \(1\leq n\leq 10^9, 1\leq k\leq 5000\) Solution ...

  4. 存储树形的数据表转为Json

    /// <summary> /// 根据DataTable生成Json树结构 /// </summary> /// <param name="tabel&quo ...

  5. 基于asp.net mvc的近乎产品开发培训课程(第三讲)

    演示产品源码下载地址:http://www.jinhusns.com/Products/Download 

  6. centos7 离线安装Ambari

    准备工作: 新下载的centos7 安装 createrepo,用于制作源 yum install createrepo 安装java (推荐 java 1.7以上版本,如果有,则跳过此步骤) yum ...

  7. CRC算法

    https://blog.csdn.net/dream_1996/article/details/73588269

  8. MVC 使用Quartz.Net组件实现定时计划任务

    最近,项目中需要执行一个计划任务,组长就让我了解一下Quartz.net 这个组件,挺简单的一个组件,实现起来特别的方便,灵活,值得推荐给大家一起学习一下这个小工具.以前我有的时候是使用定时器Time ...

  9. 浅谈一致性哈希(My转)

    一致性哈希(Consistent hashing)算法是由 MIT 的Karger 等人与1997年在一篇学术论文(<Consistent hashing and random trees: d ...

  10. 全功能开发团队(FSD)