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. bootstrap栅格系统的属性及使用

    栅格系统 媒体查询 在栅格系统中,我们在 Less 文件中使用以下媒体查询(media query)来创建关键的分界点阈值. 小屏幕(平板,大于等于 768px) @media (min-width: ...

  2. .NET环境下使用水晶报表

    .NET环境下使用水晶报表 听语音 | 浏览:3280 | 更新:2013-12-20 13:36 1 2 3 4 5 6 7 分步阅读 水晶报表(Crystal Reports)-商务智能软件,通常 ...

  3. 照猫画虎owin oauth for qq and sina

    ms随vs2013推出了mvc5,mvc5自带的模板项目中引用了新的身份认证框架 ms identity.其中owin部分实现了google,facebook,twitter等国外常见的第三方用户.可 ...

  4. tap 和click 事件区别

    clike事件和 Zepto.js 中tap的区别 首先介绍下Zepto: 最初是作为移动端开发的库,但是却可以作为JQuery轻量级的替代品,因为API和JQuery相似,而文件更小. 介绍下tap ...

  5. HNCU专题训练_线段树(2)

    1.统计颜色,或运算的运用2.区间第k大数3.一个很经典的题5.求区间相等数字的个数6.RMQ模板题,区间最大值和最小值的差 1.很好的思路,用或运算来避免左右儿子树总相同颜色的情况.由于T颜色种类最 ...

  6. 解决:maven 项目添加 pom 的 oracle 依赖

    前言:maven 项目需要在 pom 文件中添加 oracle 的依赖. 如果报错:报找不到驱动:java.lang.ClassNotFoundException: oracle.jdbc.drive ...

  7. AutoFac使用方法总结二:事件与依赖循环

         事件 AutoFac支持三种事件:OnActivating,OnActivated,OnRelease.OnActivating在注册组件使用之前会被调用,此时可以替换实现类或者进行一些其他 ...

  8. C# try catch嵌套

    try catch嵌套之后出现异常执行顺序: static void Main(string[] args) { try { Console.WriteLine("------------- ...

  9. CentOS7系列--10.1CentOS7中的GNOME桌面环境

    CentOS7中的桌面环境 1. 安装GNOME桌面环境 1.1. 列出所有安装套件 [root@appclient ~]# yum groups list Loaded plugins: faste ...

  10. python学习笔记之——python函数

    1.定义一个函数 你可以定义一个自己想要功能的函数,以下是简单的规则: 函数代码块以 def 关键词开头,后接函数标识符名称和圆括号(). 任何传入参数和自变量必须放在圆括号中间.圆括号之间可以用于定 ...