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 ...
随机推荐
- 订阅 memcached: error while loading shared libraries: libevent-2.0.so.5: cannot o解决
memcached: error while loading shared libraries: libevent-2.0.so.5: cannot o解决 memcached基本选项 -p 端口 ...
- 关于Mysql+EF6本地运行和发布没有问题,发布到服务器上出现问题的解决方案
这个问题折磨了我差不多两天,网上各种方法也找了个遍,但是都没有解决我的问题,后面通过自己仔细分析问题和排查,终于把问题解决了,以下是我的解决问题的步骤,希望能帮到各位,不要再被这些问题坑了 1,项目实 ...
- 利用SignalR来同步更新Winfrom小试
之前写了个用Socket来更新多个Winfrom的试例,这两天看了下SignalR,也用这个来试一下 SignalR 地址:https://www.asp.net/signalr 我这个也是基于 ht ...
- [C#]简单离线注册码生成与验证
本文使用RSA非对称加密和Base64简单地实现离线注册码的生成与验证功能. 主要思路就是提供者持有密钥,通过RSA加密客户机标识或时间标识,再通过Base64加密成不太难看的注册码,然后分发给客户机 ...
- Springboot拦截器未起作用
之前遇到要使用springboot拦截器却始终未生效的状况,查了网上的博客,大抵都是@Component,@Configuration注解未加,或是使用@ComponentScan增加包扫描,但是尝试 ...
- java8 lambda 表达式
lambada 表达式实质上是一个匿名方法,但该方法并非独立执行,而是用于实现由函数式接口定义的唯一抽象方法 使用 lambda 表达式时,会创建实现了函数式接口的一个匿名类实例 可以将 lambda ...
- jQuery Grid入门指南
上周需要把一个项目中的普通table改成使用jQuery插件形式的表格,找到了jqgrid这个插件,本以为找个demo,查查api就能解决,没想到还是费了一番的功夫,在这里记录总结一下. 本文实现的内 ...
- 使用iview-admin2构建的项目,热更新无法启动
原因:@vue/cli-service版本是3.0.1解决:升级@vue/cli-service到最新版本
- ANT DESIGN PRO 脚手架.... 懒人福音
早上在用蚂蚁组件,看到一个红红的 PRO , 什么鬼,点了看. https://pro.ant.design/index-cn 一脸懵逼, 中台前端??? 预览再看: 后台管理的demo , 脚手架 ...
- oracle exp dmp
exp help=yconn scott/tiger;select * from tab;create table student(sno int, sname varchar2(10), sage ...