codeforces 17D Notepad
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的更多相关文章
- CodeForces 17D Notepad(同余定理)
D. Notepad time limit per test 2 seconds memory limit per test 64 megabytes input standard input out ...
- 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 ...
- Codeforces Beta Round #17 D.Notepad 指数循环节
D. Notepad time limit per test 2 seconds memory limit per test 64 megabytes input standard input out ...
- Codeforces Beta Round #17 D. Notepad (数论 + 广义欧拉定理降幂)
Codeforces Beta Round #17 题目链接:点击我打开题目链接 大概题意: 给你 \(b\),\(n\),\(c\). 让你求:\((b)^{n-1}*(b-1)\%c\). \(2 ...
- Codeforces 1672 E. notepad.exe
题意 这是一道交互题,有n个字符串,每个字符串长度:0-2000, n :0-2000 有一个机器对他进行排版,你可以给他一个每行的最大宽度w,那么每行只能放长度为w的字符: 每行相邻两个字符串之间至 ...
- 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 ...
- 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 ...
- Codeforces 833A The Meaningless Game - 数论 - 牛顿迭代法 - 二分法
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. T ...
- Codeforces Round #426 The Meaningless Game
题目网址:http://codeforces.com/contest/834/problem/C 题目: C. The Meaningless Game Slastyona and her loyal ...
随机推荐
- [CQOI 2018]异或序列&[Codeforces 617E]XOR and Favorite Number
Description 题库链接1 题库链接2 已知一个长度为 \(n\) 的整数数列 \(a_1,a_2,\cdots,a_n\) ,给定查询参数 \(l,r\) ,问在 \([l,r]\) 区间内 ...
- Spring缓存注解@Cache,@CachePut , @CacheEvict,@CacheConfig使用
@Cacheable.@CachePut.@CacheEvict 注释介绍 表 1. @Cacheable 作用和配置方法 @Cacheable 的作用 主要针对方法配置,能够根据方法的请求参数对其结 ...
- MYSQL安装时解决要输入current root password的解决方法
在装MYSQL的时候发现要输入current root password不记得以前在电脑里装过(你的系统曾经装过MYSQL在重装就会要求输入原来设定的密码,如果是第一次安装就不会出现),在网上苦苦搜寻 ...
- HTML5的audio在手机网页上无法自动加载/播放音乐,能否实现该功能?
在IOS中第一次调用play方法播放音频会被阻止,必须得等用户有交互动作,比如touchstart,click后才能正常调用,在微信中可以通过监听WeixinJSBridgeReady事件来提前播放一 ...
- Struts2 学习笔记--Action Method--接收参数
struts2中的路径问题 注意:在jsp中”/”表示tomcat服务器的根目录,在struts.xml配置文件中”/”表示webapp的根路径,即MyEclipse web项目中的WebRoot路径 ...
- 【转】通过CountDownLatch提升请求处理速度
countdownlatch是java多线程包concurrent里的一个常见工具类,通过使用它可以借助线程能力极大提升处理响应速度,且实现方式非常优雅.今天我们用一个实际案例和大家来讲解一下如何使用 ...
- Yii 之widget
默认情况下, widget 的视图文件位于包含了widget文件的 views 子目录之下.这些视图可以通过调用 CWidget::render()渲染,这一点和控制器很相似.唯一不同的是,widge ...
- Aspose.cells常用用法1
代码: var execl_path = @"G:\zhyue\backup\项目修改-工作日常\2018-11-12 区域楼盘中心点和放大比例计算\a.xlsx"; Workbo ...
- dnspod域名解析设置
time: 2016-01-8 10:30 因为我的博客是用Github page搭建的,所以要把域名和Github_name.github.io的URL联系起来.本人实在小白一个,就纪录一下 ...
- Android Service不能再详细的教程
这篇包含了: Service后台服务.前台服务.IntentService.跨进程服务.无障碍服务.系统服务 几乎所有Android Service相关的东西. 前言 作为四大组件之一的Service ...