题意

求满足$na^n\equiv b \pmod p$的$n$的个数


因为$n \mod p ​$循环节为$p​$,$a^n\mod p​$循环节为$p-1​$,所以$na^n \mod p​$循环节为$p(p-1)​$

假设$n \mod p \equiv i,a^n\mod p\equiv a^j$ , 那么$n%p \times a^n%p\equiv b \pmod p$,得到$i \times a^j \equiv b \pmod p$,列同余方程$i \equiv b*a^{-j} \pmod p, i\equiv j \pmod {p-1}$,解得$i=(p-1)2baj+pj$,在$n$的上限内计算答案

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a, b, p, x, ans = 0;
LL quick_pow(LL x, LL y, LL mod) {
LL ret = 1;
for(; y; y >>= 1) {
if(y & 1) ret = (ret * x) % mod;
x = (x * x) % mod;
}
return ret;
}
int main() {
cin >> a >> b >> p >> x;
for(LL i = 1; i < p; ++i) {
LL inv = quick_pow(quick_pow(a, i, p), p - 2, p);
LL y = b * inv % p;
LL P = p * (p - 1);
LL r = (p * i + (p - 1) * (p - 1) % P * y) % P;
ans += x / P + (x % P >= r);
}
cout << ans << endl;
return 0;
}

【Codeforces】Round #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. cf 460 E. Congruence Equation 数学题

    cf 460 E. Congruence Equation 数学题 题意: 给出一个x 计算<=x的满足下列的条件正整数n的个数 \(p是素数,2 ≤ p ≤ 10^{6} + 3, 1 ≤ a ...

  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).E 费马小定理+中国剩余定理

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

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

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

  6. POJ 2891 Strange Way to Express Integers 中国剩余定理 数论 exgcd

    http://poj.org/problem?id=2891 题意就是孙子算经里那个定理的基础描述不过换了数字和约束条件的个数…… https://blog.csdn.net/HownoneHe/ar ...

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

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

  8. Codeforces Round #460 D. Karen and Cards

    Description Karen just got home from the supermarket, and is getting ready to go to sleep. After tak ...

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

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

随机推荐

  1. apue学习笔记(第八章 进程控制)

    本章介绍UNIX系统的进程控制,包括创建新进程.执行程序和进程终止. 进程标识 每一个进程都有一个非负整数表示的唯一进程ID,除了进程ID,每个进程还有一些其他标识符.下列函数返回这些标识符 #inc ...

  2. 如何将数据导入到hive中

    可以通过多种方式将数据导入hive表 1.通过外部表导入 用户在hive上建external表,建表的同时指定hdfs路径,在数据拷贝到指定hdfs路径的同时,也同时完成数据插入external表. ...

  3. HttpWebRequest.Proxy属性

    HttpWebRequest.Proxy默认使用IE代理,可以设置“Internet选项-Internet属性-连接-局域网设置-代理服务器”.

  4. SPA路由机制详解(看不懂不要钱~~)

    前言 总所周知,随着前端应用的业务功能起来越复杂,用户对于使用体验的要求越来越高,单面(SPA)成为前端应用的主流形式.而大型单页应用最显著特点之一就是采用的前端路由跳转子页面系统,通过改变页面的UR ...

  5. oracle 表压缩技术

    压缩表是我们维护管理中常常会用到的.以下我们看都oracle给我们提供了哪些压缩方式. 文章摘自"Oracle® Database Administrator's Guide11g Rele ...

  6. [Java] 实验4參考代码

    题目.提示.代码.解释都已公布. 提供这些的目的不是要求大家要写得像我写得这样,而是希望大家在实验后看看别人写的代码:     1. 提升理解代码的能力.     2. 不要自满于完毕题目.要明确你的 ...

  7. ExtJs5.1多选下拉框CheckComb

    ExtJs这么多个版本号了.可就是不提供多选下拉框,老外不用这个玩意吗? 5都出来这么久了,新写的项目就用5吧,把曾经Extjs4.2的时搜到前人的CheckComb改巴改巴.能用了就赶紧贴上来,没有 ...

  8. Flex版的2048游戏

    近期2048游戏好像挺火.在公交,吃饭,甚至在路上走路都有人拿着手机在玩,之前我看同事玩,认为非常幼稚,移来移去太无聊了吧 到后面自己也下了.发现确实挺无聊的,也就是在无聊的时候打发无聊的时间,后来就 ...

  9. Java的Executor框架和线程池实现原理

    Java的Executor框架 1,Executor接口 public interface Executor { void execute(Runnable command); } Executor接 ...

  10. hdu 1068 Girls and Boys 二分图的最大匹配

    题目链接:pid=1068">http://acm.hdu.edu.cn/showproblem.php? pid=1068 #include <iostream> #in ...