题目链接:

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. dreamweaver 8的替换功能

    dreamweaver 8的替换功能 下面教你用dreamweaver 8的替换功能来删除这些冗余代码. 查找范围:文件夹(然后选取你需要替换的文件夹) 搜索:源代码查找:\btppabs=" ...

  2. js call 和 apply

    前言 call 和 apply 都是为了改变某个函数运行时的 context 即上下文而存在的,换句话说,就是为了改变函数体内部 this 的指向. call 和 apply二者的作用完全一样,只是接 ...

  3. Kinect 开发 —— 开发前的准备工作

    Kinect SDK v1.5 支持托管语言和非托管语言 Xbox360的游戏是基于Xbox360开发工具包 (XDK)开发的,Xbox 360和Windows是两个完全不同的系统架构.使用Kinec ...

  4. Mysql数据库调优和性能优化

    1. 简介 在Web应用程序体系架构中,数据持久层(通常是一个关系数据库)是关键的核心部分,它对系统的性能有非常重要的影响.MySQL是目前使用最多的开源数据库,但是mysql数据库的默认设置性能非常 ...

  5. groups---输出指定用户所在组的组成员,

    groups命令   groups命令在标准输入输出上输出指定用户所在组的组成员,每个用户属于/etc/passwd中指定的一个组和在/etc/group中指定的其他组. 语法 groups(选项)( ...

  6. nginx配置静态文件服务器的一个特殊需求的探索和分享, nginx处理不同路径返回统一文件,nginx改写,跳转请求.

    最近在做一个前后端分离的个人博客,在做自己博客的时候有个想法,本来是打算用nginx作为静态文件服务器使用,django做后端程序. 我的前端页面用vue写的,结果用组件用嗨了,发现页面列表和 详情都 ...

  7. 微信小程序从零开始开发步骤(四)自定义分享的功能

    上一章节,实现了小程序的底部导航的功能,这一节开始实现一些简单的功能.本章节介绍的是小程序的自定义分享的功能. 可以分享小程序的任何一个页面给好友或群聊.注意是分享给好友或群聊,并没有分享到朋友圈.一 ...

  8. HDU——T 3746 Cyclic Nacklace

    http://acm.hdu.edu.cn/showproblem.php?pid=3746 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  9. Dos图像复制成序列

    rem 输入1.png,在当前文件下复制.0000.png--0002.png rem 注:way2是不等待0001.png运行完就開始运行下一个了. rem 假设要等待上一个运行完后,再往下顺弃运行 ...

  10. 互联网+时代IT管理者的转型

    最近,大众创业万众创新的热潮真是一浪接着一浪,它实际上是一次政府和企事业的自我改革,利用互联网+的思维与技术对生产模式.流通模式与运营模式进行全新的变革,商业的本质是没有变的,仅仅是穿了个马甲来表演. ...