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 ...
随机推荐
- [COGS 1535] [ZJOI2004]树的果实 树状数组+桶
我们用树状数组做差就可以解决一切问题,我用桶排并用此来表示出第几大就可以直接求前缀和了 #include<cstdio> #include<algorithm> #define ...
- vector 进阶
http://classfoo.com/ccby/article/jnevK #include <iostream> #include <vector> #include &l ...
- 深入理解Java虚拟机—内存管理机制
前面说过了类的加载机制,里面讲到了类的初始化中时用到了一部分内存管理的知识,这里让我们来看下Java虚拟机是如何管理内存的. 先让我们来看张图 有些文章中对线程隔离区还称之为线程独占区,其实是一个意思 ...
- Covered Points Count(思维题)
C. Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- Optimize Prime Sieve
/// A heavily optimized sieve #include <cstdio> #include <cstring> #include <algorith ...
- LwIP - 打开keepalive功能
在服务器端打开keepalive功能 1.保证LWIP_TCP_KEEPALIVE被定义为1,(这样TCP_KEEPIDLE.TCP_KEEPINTVL和TCP_KEEPCNT 设置才有效) 2. i ...
- 关于flume的几道题
1,要求:监听一个tcp,udp端口41414将数据打印在控制台 # example.conf: A single-node Flume configuration # Name the compon ...
- JavaWeb中session创建与销毁的问题
今天遇到一个奇怪的问题,自己添加了一个session的监听,用来监听在线的人数.但打开浏览器时一直没有走进这个监听中来.最后百度找到了原因: 我们一直存在一个误区,javaweb中的session什么 ...
- POJ2245 Lotto
Lotto Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6634 Accepted: 4201 Description ...
- 一道面试题:C++相比C#或者java的优势到底在哪里
被问到了这样一道面试题,当时就懵了,内心一直觉得C++肯定在很多方面要比C#或者java要牛b的. 但是真的不知道怎么回答. 问题是:你以前一直做得是.NET相关项目,现在为什么找C++开发相关工作呢 ...