题目链接:

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. EBS OAF开发中实体对象和视图对象的属性设置器

    EBS OAF开发中实体对象和视图对象的属性设置器 (版权声明.本人原创或者翻译的文章如需转载,如转载用于个人学习,请注明出处:否则请与本人联系,违者必究) 源文: Home > Oracle ...

  2. poj2486--Apple Tree(树状dp)

    Apple Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7789   Accepted: 2606 Descri ...

  3. android 二次按返回键退出client

    android中有的app退出client时弹出对话框的方法,有的是点击二次,第一次是提示用户是否退出client,第二次点击才是真正的退出app.这是用二次点击返回键的时间间隔推断, 今天就实现这简 ...

  4. UI_搭建MVC

    新建RootViewController 继承于 UIViewController 新建RootView 继承于 UIView AppDelegate.m 中引入 #import "Root ...

  5. android--动态加载、插件化

    需求驱动 随着业务发展需要和无线部门的拆分,各业务产品模块归属到各业务BU,原有无线App开发团队被分为基础框架.业务A.业务B.业务C等多个开发团队,从此App的开发和发布进入了一个全新模式.在这种 ...

  6. Android自定义组件系列【13】——Android自定义对话框如此简单

    在我们的日常项目中很多地方会用到对话框,但是Android系统为我们提供的对话框样子和我们精心设计的界面很不协调,在这种情况下我们想很自由的定义对话框,或者有的时候我们的对话框是一个图片,没有标题和按 ...

  7. Fragment-两种使用方式

    这篇我们就用实例来看看我们在代码中如何使用Fragment 一:静态添加Fragment 新建一个项目,添加两个Fragment的布局文件fragment_title,fragment_content ...

  8. 如何监控和解决SQL Server的阻塞(1) (当前阻塞)

    1. 什么是"阻塞"? 阻塞是SQL数据库应用"锁"机制的一个副作用.当一个应用请求针对某个数据库对象(例如全表,某行数据, 或者是某个数据页)加锁后,那么这个 ...

  9. call(),apply()和bind()的详解使用:

    obj.call(thisObj, arg1, arg2, ...); obj.apply(thisObj, [arg1, arg2, ...]); 两者作用一致,都是把obj(即this)绑定到th ...

  10. qrcode length overflow 生成二维码网址长度溢出解决办法

    QRCode.js is javascript library for making QRCode. QRCode.js supports Cross-browser with HTML5 Canva ...