cf 460 E. Congruence Equation 数学题
cf 460 E. Congruence Equation 数学题
题意:
给出一个x 计算<=x的满足下列的条件正整数n的个数

\(p是素数,2 ≤ p ≤ 10^{6} + 3, 1 ≤ a, b < p, 1 ≤ x ≤ 10^{12}\)
思路:
题目中存在两个循环节 \(n % p\) 和 \(a ^ n % p\), 循环节分别为\(p,p-1\)
我们枚举\(i = n\ (mod)\ (p - 1)\)
可以得到两个方程
\]
\]
令$mm = \frac{b}{a ^ i} $
设 $$n = p * k + mm , n = (p - 1) * q + i $$
于是\(p * k + mm = p * q - q + i\)
在模p意义下可以得到
\(q \equiv (i - mm)\ (mod) p\)
然后就可以根据限制条件计算出有多少个满足条件的q 即答案了
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL qpow(LL x,LL y,LL mod){
x %= mod;
LL ans = 1;
while(y){
if(y & 1) ans = ans * x % mod;
x = x * x % mod;
y >>= 1;
}
return ans;
}
int main(){
LL a,b,p,X;
cin>>a>>b>>p>>X;
LL x,y,m = b,inva = qpow(a, p - 2,p);
LL ans = 0;
for(int i = 0;i < p - 1;i++){
LL mm = (i - m + p) % p;
LL R = (floor)((1.0 * (X - i) / (p -1) - mm)/p) ;
LL L = mm / p;
// for(int j = L;j <= R;j++) cout<<(p * j + mm) * (p - 1) + i<<" ";
m = m * inva % p;
ans += R - L + 1;
}
cout<<ans<<endl;
return 0;
}
cf 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) ...
- 【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$循环 ...
- E. Congruence Equation
E. Congruence Equation 思路: 中国剩余定理 \(a^n(modp) = a^{nmod(p-1)}(modp)\),那么枚举在\([0,n-2]\)枚举指数 求\(a^i\)关 ...
- Codeforces Round #460 (Div. 2) E. Congruence Equation (CRT+数论)
题目链接: http://codeforces.com/problemset/problem/919/E 题意: 让你求满足 \(na^n\equiv b \pmod p\) 的 \(n\) 的个数. ...
- [Codeforces 919E]Congruence Equation
Description 题库链接 求满足 \[n\cdot a^n\equiv b \pmod{p}\] 的 \(n\) 的个数, \(1\leq n\leq x\) , \(a,b,p,x\) 均已 ...
- Codeforces.919E.Congruence Equation(同余 费马小定理)
题目链接 \(Description\) 给定a,b,x,p,求[1,x]中满足n*a^n ≡b (mod p) 的n的个数.\(1<=a,b<p\), \(p<=1e6+3\), ...
- Codeforces 919 E Congruence Equation
题目描述 Given an integer xx . Your task is to find out how many positive integers nn ( 1<=n<=x1&l ...
- [CF919E]Congruence Equation
题意:求关于$n$的方程$n\cdot a^n\equiv b\left(mod\ p\right)$在$[1,x]$中整数解的数量 果然是Chinese round,interesting roun ...
- Codeforces 919E Congruence Equation ( 数论 && 费马小定理 )
题意 : 给出数 x (1 ≤ x ≤ 10^12 ),要求求出所有满足 1 ≤ n ≤ x 的 n 有多少个是满足 n*a^n = b ( mod p ) 分析 : 首先 x 的范围太大了,所以使 ...
随机推荐
- 一次IPC无法创建的问题
背景说明: 后台子系统都是运行在pc上的linux 系统有多个子系统,有一个子系统负责统一启停其他子系统,这里把这个子系统称为olddriver. ol ...
- 「日常训练」 Yukari's Birthday(ZOJ-3665)
题意与分析 二分题.考虑到n的范围是\(10^{12}\),注意到等比公式\(S=a_1\frac{1-q^n}{1-q} (q\ne 1)\),可以看出,不论q有多大(1除外,这个时候\(r=1,k ...
- Appium-原理、设置
Appium是支持跨平台的移动端自动化测试框架. 下面介绍下Appium的具体工作流程: 首先,Appium server 默认监听4723端口,监听客户端的命令. 客户端指的是 我们编写的自动化测试 ...
- Appium最新的服务器初始化参数(Capability)【截止11月29日,后续最新的可以看github】
键 描述 值 automationName 自动化测试的引擎 Appium (默认)或者 Selendroid platformName 使用的手机操作系统 iOS, Android, 或者 Fire ...
- 【system.date】使用说明
对象:system.date 说明:提供一系列针对日期类型的操作 目录: 方法 返回 说明 system.date.isDate( date_string ) [True | False] 判断 ...
- GIT: 分布式开发 代码管理工具使用命令大全
代码管理工具: GIT 什么是GIT? Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目 Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常 ...
- Eclipse上安装Activiti插件
今天我们来讲下如何在Eclipse上安装Activiti插件,以后我们要用这个插件来画流程设计图: 这个插件名字是:Activiti BPMN 2.0 designer 具体使用,可以参考官方用户指南 ...
- 拥抱移动端,jQueryui触控设备兼容插件
http://touchpunch.furf.com/ ps:要FQ. jQuery UI Touch Punch Touch Event Support for jQuery UI Tested o ...
- 论文笔记:Deep Attentive Tracking via Reciprocative Learning
Deep Attentive Tracking via Reciprocative Learning NIPS18_tracking Type:Tracking-By-Detection 本篇论文地主 ...
- matlab中设置colorbar为几种规定颜色
我们可以通过修改colormap的值来达到这种目的. 一般来说colormap的值是64*3的矩阵,64代表64种颜色,3列是这种颜色的RGB值,不过归一化了. 如果你想将colorbar颜色设成6种 ...