题目链接:

http://codeforces.com/problemset/problem/919/E

题意:

让你求满足 \(na^n\equiv b \pmod p\) 的 \(n\) 的个数。

\(2 ≤ p ≤ 10^{6} + 3, 1 ≤ a, b < p, 1 ≤ x ≤ 10^{12}\).

题解:

因为:

$n \mod p $的循环节是 \(p\)

\(a^{n} \mod p\)的循环节是 \(p-1\)。(费马小定理)

所以: \(na^n \mod p​\)的循环节为 \(p*(p-1)\)。

因为 \(p\)是质数。

假设: \(n \mod p \equiv i, a^n\mod p\equiv a^j\).

\(a^n \mod p \equiv i\) ----①

$a^n\mod p\equiv a^j $ ----②

\(na^n\equiv b \pmod p\) ----③

可以得到: \(i \times a^j \equiv b \pmod p\).

我们现在枚举的\(a^n\) 中的 \(n\) 为 \(j\) , 满足 \(n \times a^n\ mod\ p\ = \ b\) 的 \(n\) 为 \(i\).

列出同余方程:

$i \equiv b*a^{-j} \pmod p $ ---①

\(i\equiv j \pmod {p-1}\) ---②

利用 \(CRT\) 可以解出 :\(i=(p-1)^2ba^{-j}+pj\) ,其中 \(a^{-j}\) 是$ a^{j}$ 在 $\mod p $意义下的逆元。

因为在所有 \(<=x\) 的 \(i\) 的倍数都满足条件,除法统计一下即可。

复杂度:\(O(p*logp)\)

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll; ll qpower(ll a,ll b, ll mod)
{
ll ans = 1;
while(b){
if(b&1) ans = ans * a % mod;
b>>=1;
a=a*a%mod;
}
return ans;
}
ll a,b,mod,x;
int main(int argc, char const *argv[]) {
std::cin >> a >> b >> mod >> x;
ll ans = 0;
for(int i = 1;i <= mod-1;i++) {
ll c = qpower( qpower(a, i , mod) , mod - 2, mod) * b % mod;
ll n = ((mod-1) * (mod-1) * c + mod * i) % (mod * (mod-1));
ans += ( x / (mod * (mod-1)) ) + (x % (mod * (mod-1)) >= n );
}
std::cout << ans << '\n';
return 0;
}

Codeforces Round #460 (Div. 2) E. Congruence Equation (CRT+数论)的更多相关文章

  1. Codeforces Round #460 (Div. 2).E 费马小定理+中国剩余定理

    E. Congruence Equation time limit per test 3 seconds memory limit per test 256 megabytes input stand ...

  2. [Codeforces]Codeforces Round #460 (Div. 2)

    Supermarket 找最便宜的就行 Solution Perfect Number 暴力做 Solution Seat Arrangement 注意当k=1时,横着和竖着是同一种方案 Soluti ...

  3. Codeforces Round #460 (Div. 2) ABCDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8397685.html 2018-02-01 $A$ 题意概括 你要买$m$斤水果,现在有$n$个超市让你选择. ...

  4. Codeforces Round #460 (Div. 2) 前三题

    Problem A:题目传送门 题目大意:给你N家店,每家店有不同的价格卖苹果,ai元bi斤,那么这家的苹果就是ai/bi元一斤,你要买M斤,问最少花多少元. 题解:贪心,找最小的ai/bi. #in ...

  5. Codeforces Round #460 (Div. 2)

    A. Supermarket We often go to supermarkets to buy some fruits or vegetables, and on the tag there pr ...

  6. Codeforces Round #460 (Div. 2): D. Substring(DAG+DP+判环)

    D. Substring time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...

  7. Codeforces Round #460 (Div. 2)-D. Substring

    D. Substring time limit per test3 seconds memory limit per test256 megabytes Problem Description You ...

  8. Codeforces Round #460 (Div. 2)-C. Seat Arrangements

    C. Seat Arrangements time limit per test1 second memory limit per test256 megabytes Problem Descript ...

  9. Codeforces Round #460 (Div. 2)-B. Perfect Number

    B. Perfect Number time limit per test2 seconds memory limit per test256 megabytes Problem Descriptio ...

随机推荐

  1. b模式处理文件

    1.读 f=open('cheng','rb') date=f.read() print(date.decode()) 2.写 f=open('cheng','ab') f.write('chengz ...

  2. Redisclient连接方式Hiredis简单封装使用,连接池、屏蔽连接细节

    工作须要对Hiredis进行了简单封装,实现功能: 1.API进行统一,对外仅仅提供一个接口. 2.屏蔽上层应用对连接的细节处理: 3.底层採用队列的方式保持连接池,保存连接会话. 4.重连时採用时间 ...

  3. VS NuGet使用

    通过这个可以自动联网下载内容! 很方便! 工具->NuGet包管理工具->程序包管理器控制台

  4. 三个角度解构云计算,商业驱动or技术驱动?

    从云计算的使用者到云服务的输出者,大多互联网公司在过去一年完成了角色的转换,也让云计算的未来更加扑朔迷离.不过,抛却进入时间这个评判因素,单从技术和商业化的角度来解构云计算的话,对于云计算的格局以及未 ...

  5. 运动识别之HOJ3D和HMM

    http://cvrc.ece.utexas.edu/Publications/Xia_HAU3D12.pdf   View Invariant Human Action Recognition Us ...

  6. storm单机运行与集群运行问题

    使用trident接口时,storm读取kafka数据会将kafka消费记录保存起来,将消费记录的位置保存在tridentTopology.newStream()的第一个参数里, 如果设置成从头开始消 ...

  7. docker部署mysql 实现远程连接

    1. docker search mysql    # 查看mysql版本 2. docker pull mysql:5.7   # 拉取mysql 5.7 3. docker images  # 查 ...

  8. Python线程池任务

    #!/usr/bin/env python # -*- coding:utf-8 -*- from concurrent.futures import ThreadPoolExecutor #线程池, ...

  9. metadata 和 routing

    虽然在刚开始源码概述时把代码分为分布式和数据两部分,但是它们的界限并不明显.之前这几篇可以说是这两部分的衔接.我们在快速接近数据(index)部分.本篇分析一下之前分析cluster遗留下的问题:Me ...

  10. Python: scikit-image gamma and log 对比度调整

    这个函数,主要用来做对比度调整,利用 gamma 曲线 或者 log 函数曲线, gamma 函数的表达式: y=xγ, 其中, x 是输入的像素值,取值范围为 [0−1], y 是输出的像素值,通过 ...