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. Android官方开发文档Training系列课程中文版:目录

    Android官方开发文档Training系列课程中文版:目录   引言 在翻译了一篇安卓的官方文档之后,我觉得应该做一件事情,就是把安卓的整篇训练课程全部翻译成英文,供国内的开发者使用,尤其是入门开 ...

  2. c# enum 解析

    解析定义的枚举 public enum OrderPaymentStatus { /// <summary> /// 未支付 /// </summary> [Descripti ...

  3. <cerrno>

    文件头名称: <cerrno>(errno.h) 文件头描述: 文件内定义了如下的宏  errno 最后一个错误代码 加上其他至少的三个宏常量:EDOM,ERANGE 和EILSEQ 宏定 ...

  4. [SHELL]shell中变量的使用

    1.输出变量 : #! /bin/bash my_var=BOB echo $my_var echo "hi,$my_var" echo "the price is \$ ...

  5. sql server存储特殊字符解决办法

    好久没来院子了,最近在学java了,再加上项目比较紧,最近都没怎么上,其实这几天在项目中学到不少东西,都能写下来,但是久而久之就忘了,还是得养成及时总结的好习惯啊,还有有时间一定要把那个小项目整理下来 ...

  6. kubernetes相关

    1.获取client , api-server 加token 或in-cluster方式 2.所有对象均有list update get 等方法 3.对象属性源码追踪,yaml与源码一一对应 4.一些 ...

  7. 为什么安装beego和框架的失败 以及常用命令

    1.安装了几个版本,版本之间相互影响. 把没用的删掉 2.网上找的教程存在问题. 都是相互抄袭.最权威的还是官网. which go rm -rf test/ echo path 获取路径 vim ~ ...

  8. .Net并行编程 - Reactive Extensions(Rx)并发浅析

    关于Reactive Extensions(Rx) 关于Reactive Extensions(Rx),先来看一下来自微软的官方描述: The Reactive Extensions (Rx) is ...

  9. POJ 2455 Secret Milking Machine(最大流+二分)

    Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...

  10. Redis 错误摘记篇

    yum安装的redis提示如下报错,大概意思就是配置文件和redis-server进程文件版本不一致.. [root@vm-10-104-28-24 yum.repos.d]# redis-serve ...