【Codeforces】Round #460 E - Congruence Equation 中国剩余定理+数论
题意
求满足$na^n\equiv b \pmod p$的$n$的个数
因为$n \mod p $循环节为$p$,$a^n\mod p$循环节为$p-1$,所以$na^n \mod p$循环节为$p(p-1)$
假设$n \mod p \equiv i,a^n\mod p\equiv a^j$ , 那么$n%p \times a^n%p\equiv b \pmod p$,得到$i \times a^j \equiv b \pmod p$,列同余方程$i \equiv b*a^{-j} \pmod p, i\equiv j \pmod {p-1}$,解得$i=(p-1)2baj+pj$,在$n$的上限内计算答案
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a, b, p, x, ans = 0;
LL quick_pow(LL x, LL y, LL mod) {
LL ret = 1;
for(; y; y >>= 1) {
if(y & 1) ret = (ret * x) % mod;
x = (x * x) % mod;
}
return ret;
}
int main() {
cin >> a >> b >> p >> x;
for(LL i = 1; i < p; ++i) {
LL inv = quick_pow(quick_pow(a, i, p), p - 2, p);
LL y = b * inv % p;
LL P = p * (p - 1);
LL r = (p * i + (p - 1) * (p - 1) % P * y) % P;
ans += x / P + (x % P >= r);
}
cout << ans << endl;
return 0;
}
【Codeforces】Round #460 E - Congruence Equation 中国剩余定理+数论的更多相关文章
- Codeforces Round #460 E. Congruence Equation
Description 题面 \(n*a^n≡b (\mod P),1<=n<=x\) Solution 令 \(n=(P-1)*i+j\) \([(P-1)*i+j]*a^{[(P-1) ...
- cf 460 E. Congruence Equation 数学题
cf 460 E. Congruence Equation 数学题 题意: 给出一个x 计算<=x的满足下列的条件正整数n的个数 \(p是素数,2 ≤ p ≤ 10^{6} + 3, 1 ≤ a ...
- Codeforces Round #460 (Div. 2) ABCDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8397685.html 2018-02-01 $A$ 题意概括 你要买$m$斤水果,现在有$n$个超市让你选择. ...
- Codeforces Round #460 (Div. 2).E 费马小定理+中国剩余定理
E. Congruence Equation time limit per test 3 seconds memory limit per test 256 megabytes input stand ...
- [Codeforces]Codeforces Round #460 (Div. 2)
Supermarket 找最便宜的就行 Solution Perfect Number 暴力做 Solution Seat Arrangement 注意当k=1时,横着和竖着是同一种方案 Soluti ...
- POJ 2891 Strange Way to Express Integers 中国剩余定理 数论 exgcd
http://poj.org/problem?id=2891 题意就是孙子算经里那个定理的基础描述不过换了数字和约束条件的个数…… https://blog.csdn.net/HownoneHe/ar ...
- Codeforces Round #460 (Div. 2) E. Congruence Equation (CRT+数论)
题目链接: http://codeforces.com/problemset/problem/919/E 题意: 让你求满足 \(na^n\equiv b \pmod p\) 的 \(n\) 的个数. ...
- Codeforces Round #460 D. Karen and Cards
Description Karen just got home from the supermarket, and is getting ready to go to sleep. After tak ...
- Codeforces Round #460 (Div. 2) 前三题
Problem A:题目传送门 题目大意:给你N家店,每家店有不同的价格卖苹果,ai元bi斤,那么这家的苹果就是ai/bi元一斤,你要买M斤,问最少花多少元. 题解:贪心,找最小的ai/bi. #in ...
随机推荐
- 【Python数据分析】IPython快捷键
命令 说明 CTRL+P(或向上箭头) 后向搜索命令历史中以当前输入的文本开头的命令 CTRL+N(或向下箭头) ...
- PM2.5
http://baike.baidu.com/view/1423678.htm PM2.5是指大气中直径小于或等于2.5微米的颗粒物,也称为可入肺颗粒物.虽然PM2.5只是地球大气成分中含量很少的组分 ...
- Coursera上的machine learning学完啦
Coursera上的第一门公开课最终要结束啦-- 全部的代码http://download.csdn.net/detail/abcd1992719g/7306053 老师的Octave代码很赞.框架打 ...
- 光盘yum源搭建步骤
- 【强网杯2018】Gamebox
参考: https://www.cnblogs.com/hac425/p/9416787.html http://tacxingxing.com/2018/03/28/2018qwb/ 事后复盘pwn ...
- iOS开发人员程序许可协议
请细致阅读以下的许可协议条款和条件之前下载或使用苹果软件. 这些条款和条件构成你和苹果之间的法律协议. iOS开发人员程序许可协议 目的 你想使用苹果软件(例如以下定义)来开发一个或多个应 ...
- Makefile调用shell应该注意的地方
转载:http://blog.csdn.net/ninlei0115/article/details/9732191 1.在Makefile中只能在target中调用Shell脚本,其他地方是不能输出 ...
- 【转】php和java之间rsa加密互通
以下是php封装好的类,引入即可使用 <?php /** * 作者:pjp * 邮箱:vippjp@163.com */ class RSA{ private $privateKey='';// ...
- yum 安装apache php 使php支持memcached扩展
在公司上新项目的时候,无论生产环境还是测试环境,都会让运维安装php 环境(lamp/lnmp),并让php支持memcached 的扩展.这里搭建php环境其实主要就是搭建apache 和php.m ...
- wamp环境配置;转自发瑞的博客(www.cnblogs.com/cyrfr/p/6483529.html)
php手动搭建环境有好多种组合,版本号不一致,会导致搭建失败. 我搭建的组合是: php5.6+MySQL5.6+Apache2.4的组合. 一.PHP语言包下载 首先从官网上下载php5.6 htt ...