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)\)

可以得到两个方程

\[n\ \equiv\ i\ mod\ (p-1)
\]

\[n \equiv \frac{b}{a ^ i}\ mod\ p
\]

令$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 数学题的更多相关文章

  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. 【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​$循环 ...

  3. E. Congruence Equation

    E. Congruence Equation 思路: 中国剩余定理 \(a^n(modp) = a^{nmod(p-1)}(modp)\),那么枚举在\([0,n-2]\)枚举指数 求\(a^i\)关 ...

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

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

  5. [Codeforces 919E]Congruence Equation

    Description 题库链接 求满足 \[n\cdot a^n\equiv b \pmod{p}\] 的 \(n\) 的个数, \(1\leq n\leq x\) , \(a,b,p,x\) 均已 ...

  6. 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\), ...

  7. Codeforces 919 E Congruence Equation

    题目描述 Given an integer xx . Your task is to find out how many positive integers nn ( 1<=n<=x1&l ...

  8. [CF919E]Congruence Equation

    题意:求关于$n$的方程$n\cdot a^n\equiv b\left(mod\ p\right)$在$[1,x]$中整数解的数量 果然是Chinese round,interesting roun ...

  9. Codeforces 919E Congruence Equation ( 数论 && 费马小定理 )

    题意 : 给出数 x (1 ≤ x ≤ 10^12 ),要求求出所有满足 1 ≤ n ≤ x 的 n 有多少个是满足 n*a^n  = b ( mod p ) 分析 : 首先 x 的范围太大了,所以使 ...

随机推荐

  1. YUM本地源制作与yum网络版仓库

    1.修改本机上的YUM源配置文件,将源指向自己 cd /etc/yum.repos.d/ 备份原有的YUM源的配置文件 rename .repo .repo.bak * rename CentOS-M ...

  2. selenium,unittest——两个class连续运行

    将多个class放在一个文件内一起运行,这是一个多用例不同网站进行测试的方法 #encoding=utf-8from selenium import webdriverimport time,unit ...

  3. 基于Python的接口自动化

    第一步 Python的安装配置 打开官网: https://www.python.org/downloads/ 目前官网上已经更新到3.6.1啦,有两个版本,大家可以按自己喜欢的去下载,我自己选择的是 ...

  4. mysql bin log配置及查看

    mysql执行sql可以通过设置mysql bin 日志进行记录查看   mysql bin日志配置如下:   log_bin:on log_bin_basename:bin文件路径及名前缀(/var ...

  5. Python爬虫模拟登录带验证码网站

    问题分析: 1.爬取网站时经常会遇到需要登录的问题,这是就需要用到模拟登录的相关方法.python提供了强大的url库,想做到这个并不难.这里以登录学校教务系统为例,做一个简单的例子. 2.首先得明白 ...

  6. github 使用“git commit -m"命令时候出现的一个小问题

    git commit -m 使用问题 今天提交文件到github,步骤是: git add abc.py (abc.py是我当前随意写的一个文件名) git commit -m 'add codes ...

  7. 微软的XML可视化编辑器:XML Notepad 2007

    最近项目需要定义xml协议格式,编写xml文件比较多,之前使用xml spy工具,但是不够轻量级. 微软提供的xml nodepad 2007很实用,希望能给大家提供帮助. 运行后的界面 下载地址:h ...

  8. Hadoop源码解析 1 --- Hadoop工程包架构解析

    1 Hadoop中各工程包依赖简述     Google的核心竞争技术是它的计算平台.Google的大牛们用了下面5篇文章,介绍了它们的计算设施.     GoogleCluster: http:// ...

  9. Huffuman树

    问题描述 Huffman树在编码中有着广泛的应用.在这里,我们只关心Huffman树的构造过程. 给出一列数{pi}={p0, p1, …, pn-1},用这列数构造Huffman树的过程如下: 1. ...

  10. C++第一次课堂作业 circle

    Github上的代码提交