Codeforces 919 E Congruence Equation
题目描述
Given an integer xx . Your task is to find out how many positive integers nn ( 1<=n<=x1<=n<=x ) satisfy
where a,b,pa,b,p are all known constants.
输入输出格式
输入格式:
The only line contains four integers a,b,p,xa,b,p,x ( 2<=p<=10^{6}+32<=p<=106+3 , 1<=a,b<p1<=a,b<p , 1<=x<=10^{12}1<=x<=1012 ). It is guaranteed that pp is a prime.
输出格式:
Print a single integer: the number of possible answers nn .
输入输出样例
2 3 5 8
2
4 6 7 13
1
233 233 10007 1
1
说明
In the first sample, we can see that n=2n=2 and n=8n=8 are possible answers.
利用同余乱搞即可,系数是mod p的同余系,指数是mod (p-1)的同余系。
不过写之前一定要想好,不然特别容易写错(细节略多)。。。
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long
#define maxn 1000010
using namespace std;
ll ans,inv[maxn],b,d;
ll ci[maxn],p,tp; inline void init(const ll ha){
ci[0]=1;
for(int i=1;i<ha;i++) ci[i]=ci[i-1]*d%ha;
inv[1]=1;
for(int i=2;i<ha;i++) inv[i]=-inv[ha%i]*(ha/i)%ha+ha;
} inline void solve(const ll ha){
ll tmpc,tmpd;
ll basec=(tp+1)/(ha-1),lefc=tp+1-basec*(ha-1);
//basec表示指数上有多少个完整的循环节
//lefc表示最后多出来的可以走的步数
for(int i=p-2;i>=0;i--){
int to=b*inv[ci[i]]%ha;
tmpc=basec+(i<lefc);
//tmpc是计算a^i这个数出现的次数
tmpd=tmpc/ha+((i-to+ha)%ha<tmpc%ha);
//因为每次指数对应的系数都会-1,
//所以就相当于计算在系数的同余系下
//从i开始倒退走tmp-1步能走到to多少次
ans+=tmpd;
}
} int main(){
scanf("%lld%lld%lld%lld",&d,&b,&p,&tp);
init(p);
solve(p);
printf("%lld\n",ans);
return 0;
}
Codeforces 919 E Congruence Equation的更多相关文章
- cf 460 E. Congruence Equation 数学题
cf 460 E. Congruence Equation 数学题 题意: 给出一个x 计算<=x的满足下列的条件正整数n的个数 \(p是素数,2 ≤ p ≤ 10^{6} + 3, 1 ≤ a ...
- E. Congruence Equation
E. Congruence Equation 思路: 中国剩余定理 \(a^n(modp) = a^{nmod(p-1)}(modp)\),那么枚举在\([0,n-2]\)枚举指数 求\(a^i\)关 ...
- Codeforces Round #460 (Div. 2) E. Congruence Equation (CRT+数论)
题目链接: http://codeforces.com/problemset/problem/919/E 题意: 让你求满足 \(na^n\equiv b \pmod p\) 的 \(n\) 的个数. ...
- [Codeforces 919E]Congruence Equation
Description 题库链接 求满足 \[n\cdot a^n\equiv b \pmod{p}\] 的 \(n\) 的个数, \(1\leq n\leq x\) , \(a,b,p,x\) 均已 ...
- 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) ...
- 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\), ...
- 【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$循环 ...
- Codeforces 919E Congruence Equation ( 数论 && 费马小定理 )
题意 : 给出数 x (1 ≤ x ≤ 10^12 ),要求求出所有满足 1 ≤ n ≤ x 的 n 有多少个是满足 n*a^n = b ( mod p ) 分析 : 首先 x 的范围太大了,所以使 ...
- Codeforces Little Dima and Equation 数学题解
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
随机推荐
- [CERC2017]Intrinsic Interval——扫描线+转化思想+线段树
[CERC2017]Intrinsic Interval https://www.luogu.org/blog/ywycasm/solution-p4747# 这种“好的区间”,见得还是比较多的了. ...
- fresco的使用教程
1.加载依赖 api 'org.xutils:xutils:3.5.0' 2.创建一个myapplication public class MyApplication extends Applicat ...
- 使用MAT分析内存泄露
使用MAT分析内存泄露 对于大型服务端应用程序来说,有些内存泄露问题很难在测试阶段发现,此时就需要分析JVM Heap Dump文件来找出问题.随着单机内存越来越大,应用heap也开得越来越大,动辄十 ...
- Linux shell命令无法使用
配置java环境变量时,把PATH=$PATH:$HOME/bin中的冒号“:”错写成分号“;”.导致变量PATH配置错误,不能正确找到shell命令的文件位置.把/etc/profile 中java ...
- a标签的download属性简介
最近在工作中需要一个前端直接下载静态文件的需求,之前有粗略的了解过a标签的download属性,通过download和href属性可以实现文件的下载. 简介 HTML <a> 元素 (或锚 ...
- CSS盒模型之margin解析
原文链接:http://www.jianshu.com/p/ccb534e9b588 文章分为: margin的使用 margin的叠压现象 margin的子债父偿现象 一.margin的使用 HTM ...
- NodeJS概述
NodeJS中文API 一.概述 Node.js 是一种建立在Google Chrome’s v8 engine上的 non-blocking (非阻塞), event-driven (基于事件的) ...
- 【bzoj1010-toy】斜率优化入门模板
dsy1010: [HNOI2008]玩具装箱 [题目描述] 有n个数,分成连续的若干段,每段(假设从第j个到第i个组成一段)的分数为 (X-L)^2,X为j-i+Sigma(Ck) i<=k& ...
- [POJ3237]Tree解题报告|树链剖分|边剖
关于边剖 之前做的大多是点剖,其实转换到边剖非常简单. 我的做法是每个点的点权记录其到父亲节点的边的边权. 只要solve的时候不要把最上面的点记录在内就可以了. Tree Description Y ...
- wiki1285
2013-09-21 16:50 裸 //By BLADEVIL var n :longint; i :longint; x, y :longint; t, tot :longint; key, s, ...