博客
关于我
Codeforces Beta Round #17 D. Notepad 欧拉降幂
阅读量:632 次
发布时间:2019-03-14

本文共 1640 字,大约阅读时间需要 5 分钟。

原题链接:

目录

题意

求 (b-1) * b n-1 % c,b∈[2,101000000 ],n∈[1, 101000000 ]

分析

非常裸的欧拉降幂

在这里插入图片描述
根据定义可以化简n-1,特殊的b小于φ(m)的情况注意一下

b直接边读入边取膜即可

Code

#include 
using namespace std;//#define ACM_LOCAL#define fi first#define se second#define il inline#define re registertypedef long long ll;typedef pair
PII;typedef unsigned long long ull;const int N = 2e5 + 10;const int M = 1e6 + 10;const ll INF = 1e18 + 5;const double eps = 1e-5;const int MOD = 998244353;ll init(ll n) { ll m = (int)sqrt(n + 0.5); ll ans = n; for (ll i = 2; i <= m; ++ 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 ksm(ll a, ll b, ll mm) { ll res = 1, base = a; while (b) { if (b & 1) res = res * base % mm; base = base * base % mm; b >>= 1; } return res;}void solve() { string b, n; cin >> b >> n; ll c; cin >> c; ll mm = init(c); ll b_1, b_ = 0;//取b-1,b的值 for (int i = 0; i < b.size(); i++) b_ = b_ * 10 + (b[i] - '0'), b_ %= c; b_1 = (b_ - 1 + c) % c; ll n_1 = 0, flag = 0;//取n-1的值 for (int i = 0; i < n.size(); i++) { n_1 = n_1 * 10 + (n[i] - '0'); if (n_1 - 1 >= mm) n_1 %= mm, flag = 1; } n_1 = (n_1 - 1 + mm) % mm; if (flag) n_1 += mm; ll ans = ksm(b_, n_1, c); ans = ans * b_1 % c; if (ans == 0) cout << c << endl; else cout << ans << endl;}signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);#ifdef ACM_LOCAL freopen("input", "r", stdin); freopen("output", "w", stdout);#endif solve();}

转载地址:http://pmcoz.baihongyu.com/

你可能感兴趣的文章
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump 导出数据库中每张表的前n条
查看>>
mysqldump: Got error: 1044: Access denied for user ‘xx’@’xx’ to database ‘xx’ when using LOCK TABLES
查看>>