【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 ...
随机推荐
- 搭建局域网maven仓库
第一步: 下载Nexus http://nexus.sonatype.org/downloads/下载最新版本 解压缩到任意目录,我的直接解压到了E盘---------->E:\nexus-2. ...
- Leet Code OJ 237. Delete Node in a Linked List [Difficulty: Easy]
题目: Write a function to delete a node (except the tail) in a singly linked list, given only access t ...
- 开发ActiveX控件调用另一个ActiveX系列2——调试ActiveX
关于调试ActiveX控件,有若干方法,例如可以建一个MFC工程调用调试,我则倾向于使用附加到浏览器进程,因为浏览器才是真正运行的环境. 打开加载ActiveX的目标页面,当然希望我们的调试内容不是自 ...
- ReentrentLock重入锁
ReentrentLock lock=new ReentrentLock(); lock.lock(); //锁的代码 finally{ lock.unlock(); } ReentrentLock ...
- 从epoll构建muduo-12 多线程入场
mini-muduo版本号传送门 version 0.00 从epoll构建muduo-1 mini-muduo介绍 version 0.01 从epoll构建muduo-2 最简单的epoll ve ...
- linux SPI驱动——spidev之driver(六)
一: spidev_init注册spidev 1: static int __init spidev_init(void) 2: { 3: int status; 4: 5: /* Claim o ...
- rpm包查看和解压(转)
From:http://www.51testing.com/html/57/28557-205195.html 查看rpm包内容: rpm -qpl *.rpm 解压rpm包: rpm2cpio *. ...
- WPF学习之深入浅出话模板
图形用户界面应用程序较之控制台界面应用程序最大的好处就是界面友好.数据显示直观.CUI程序中数据只能以文本的形式线性显示,GUI程序则允许数据以文本.列表.图形等多种形式立体显示. 用户体验在GUI程 ...
- php 算法之------------怎样打印出下图
自己偶尔看到了下图.于是用php打印出下图. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGluZ2ppZ29uZ3Np/font/5a6L5L2T/f ...
- 微信小程序设置控件权重
项目中最常用的两种布局方式,水平布局和垂直布局,在微信小程序中实现起来也比较简单. 1.横向水平布局: 实现水平布局,需要四个view容器组件,其中一个是父容器.如下: & ...