题意

求满足$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 中国剩余定理+数论的更多相关文章

  1. 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) ...

  2. cf 460 E. Congruence Equation 数学题

    cf 460 E. Congruence Equation 数学题 题意: 给出一个x 计算<=x的满足下列的条件正整数n的个数 \(p是素数,2 ≤ p ≤ 10^{6} + 3, 1 ≤ a ...

  3. Codeforces Round #460 (Div. 2) ABCDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8397685.html 2018-02-01 $A$ 题意概括 你要买$m$斤水果,现在有$n$个超市让你选择. ...

  4. Codeforces Round #460 (Div. 2).E 费马小定理+中国剩余定理

    E. Congruence Equation time limit per test 3 seconds memory limit per test 256 megabytes input stand ...

  5. [Codeforces]Codeforces Round #460 (Div. 2)

    Supermarket 找最便宜的就行 Solution Perfect Number 暴力做 Solution Seat Arrangement 注意当k=1时,横着和竖着是同一种方案 Soluti ...

  6. POJ 2891 Strange Way to Express Integers 中国剩余定理 数论 exgcd

    http://poj.org/problem?id=2891 题意就是孙子算经里那个定理的基础描述不过换了数字和约束条件的个数…… https://blog.csdn.net/HownoneHe/ar ...

  7. Codeforces Round #460 (Div. 2) E. Congruence Equation (CRT+数论)

    题目链接: http://codeforces.com/problemset/problem/919/E 题意: 让你求满足 \(na^n\equiv b \pmod p\) 的 \(n\) 的个数. ...

  8. 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 ...

  9. Codeforces Round #460 (Div. 2) 前三题

    Problem A:题目传送门 题目大意:给你N家店,每家店有不同的价格卖苹果,ai元bi斤,那么这家的苹果就是ai/bi元一斤,你要买M斤,问最少花多少元. 题解:贪心,找最小的ai/bi. #in ...

随机推荐

  1. 命令行编译sass

    一.安装ruby1.需要的软件设备: 2.安装过程:点击上图“应用程序”安装即可,注意安装过程中其中三项都需要打上勾.如若没有三项都打上勾则需要修改环境变量中的path路径后添加一个分号. 3.打开c ...

  2. git 操作分支

    1. git 查看本地分支:git branch 2. git 查看所有分支:git branch -a 3. git 新建本地分支:git branch branchName 4. git 新建分支 ...

  3. Java实现分布式锁方式

    1.数据库乐观锁 2.redis 3.zookeeper

  4. mybatis的两种分页方式:RowBounds和PageHelper

    原理:拦截器. 使用方法: RowBounds:在mapper.java中的方法中传入RowBounds对象. RowBounds rowBounds = new RowBounds(offset, ...

  5. Window下安装Gradle并在IDEA中配置

    真是作死啊,Maven都只是用得半瓢水,还来搞Gradle,小心撩得一身骚啊. 下载Gradle 下载页面为:https://gradle.org/releases/ Gradle 4.1的下载地址: ...

  6. linux SPI驱动——spi协议(一)

    一:SPI简介以及应用 SPI, Serial Perripheral Interface, 串行外围设备接口, 是 Motorola 公司推出的一种同步串行接口技术. SPI 总线在物理上是通过接在 ...

  7. 讲真,你是因为什么才买华为P20系列手机!

    华为P20系列手机上市两个半月发货600万台!600万台?!看到这个亮瞎我钛合金狗眼的数据,且容我掰着手指脚趾算一下,算了,还是容我毫不夸张的感叹一句吧:华为做手机不用桨,不需风,全靠“浪”……. 两 ...

  8. PowerBuilder -- 其他

    判断某键是否被按下 KeyDown ( keycode ) 继承问题 如果是 uf_1是函数呢   你在父类UO_1的uf_1里面 写了代码,只要在子类UO_2的uf_1写了代码,默认是覆盖(over ...

  9. 用户对变量或寄存器进行位操作 、“|=”和“&=~”操作

    给定一个整型变量a,写两段代码,第一个设置a的bit 3,第二个清除a的bit 3.在以上两个操作中,要保持其他位不变. 答案: ----------------------------------- ...

  10. l两张图片轮播

    在head里面加 <script language="javascript"> function scroll(spanlevel) { if (spanlevel.s ...