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 的范围太大了,所以使 ...
随机推荐
- javaweb(九)—— 通过Servlet生成验证码图片
一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:
- Linux命令应用大词典-第41章 MySQL数据库
41.1 mysqld_safe:MySQL服务器启动脚本 41.2 mysql_install_db:初始化MySQL数据目录 41.3 mysqlshow:显示MySQL数据库结构 41.4 my ...
- CentOS 7.2-编译安装zabbix 3.4
起因: 前面已经使用yum安装了zabbix 3.4了,准备去交差了,交差时老大明确要求必须使用编译安装,统一放在/usr/local目录下.... 重来吧!! 一.环境说明 本次安装使用CentOS ...
- 腾讯云ubuntu安装使用MySQL
安装步骤 ubuntu@VM---ubuntu:~$ sudo apt-get install mysql-server (密码: root/root) ubuntu@VM---ubuntu:~$ s ...
- 一个五位数ABCDE乘以9,得到EDCBA,求此五位数
此题是面试时某面试官突然抛出的,要求逻辑分析推导,不许编码,5分钟时间算出来最终结果,当然,最终没有完全推算出来 下面是编码实现 #一个五位数ABCDE*9=EDCBA,求此数 for a in ra ...
- visionpro吧-百度贴吧
Halcon,Visionpro视频教程,观看下载地址:http://www.211code.com
- kaldi - Online Audio Server(服务器客户端建立方法-旧版在线解码)
目录 一.服务器客户端识别系统建立方法 1. Command line to start the server(服务器端启动方式): 2. Command line to start the clie ...
- 20162328蔡文琛week02
学号 20162328 <程序设计与数据结构>第2周学习总结 教材学习内容总结 这周学习了课本中的第二章内容,比起第一章,本章难度有略微底稿,从刚开始的显示字符转变为简单的加减乘除运算,经 ...
- 20145214 《Java程序设计》第7周学习总结
20145214 <Java程序设计>第7周学习总结 教材学习内容总结 时间的度量 格林威治标准时间(GMT),现已不作为标准时间使用,即使标注为GMT(格林威治时间),实际上谈到的的是U ...
- Java Class Object
Object类 它是所有类的基类. public class Person { } //实际上是 public class Person extends Object { } Object类的方法 t ...