[ 数论 ] Codeforces919E Congruence Equation
假设 n=Ap+B(B<p) n = A p + B ( B < p ) n=Ap+B(B
B·a^{Ap+B}\equiv b ~(~mod~p~)
B·a^{A+B}\equiv b ~(~mod~p~)
B·a^B·b^{-1}\equiv (a^{-1})^A~(~mod~p~)
然后枚举 B B B 就好了。时间复杂度 O(p)" role="presentation" style="position: relative;">O(p)O(p)O(p) 。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,Ans;
int a,inva,b,p,tot;
int A,B;
int f[1000010];
inline int Pow(int x,int y){int Ans=1;for(;y;y>>=1,x=1ll*x*x%p)if(y&1)Ans=1ll*Ans*x%p;return Ans;
}
inline ll Calc(int x,int y){if(y==-1)return 0;ll r=(n-x)/p;if(r<tot)return (y<=r);return (r-y)/tot+1;
}
int main(){scanf("%d%d%d%I64d",&a,&b,&p,&n);inva=Pow(a,p-2);memset(f,-1,sizeof(f));int t=1;for(int i=0;;i++){if(f[t]==-1)f[t]=i;else{tot=i;break;}t=1ll*t*inva%p;}t=Pow(b,p-2);for(int i=0;i<p&&i<=n;i++,t=1ll*t*a%p){int tmp=1ll*i*t%p;Ans+=Calc(i,f[tmp]);}cout<<Ans<<endl;return 0;
}
[ 数论 ] Codeforces919E Congruence Equation相关推荐
- codeforces 919E Congruence Equation
E. Congruence Equation time limit per test 3 seconds memory limit per test 256 megabytes input stand ...
- [2.7]【CF933A】A Twisty Movement【CF926B】Add Points【CF917A】The Monster【CF919E】Congruence Equation
文章目录 T1:A Twisty Movement 题目 题解 code T2:Add Points 题目 题解 code T3:The Monster 题目 题解 code T4:Congruenc ...
- Codeforces Round #460 (Div. 2): E. Congruence Equation(枚举)
题意:给出a, b, p, x,求有多少个n满足①n*a^n%p==b:②n<=x 思路:先要知道一个很简单的性质:a^n%p的值一定存在循环节(n=0就进入循环),且周期T一定是p-1的约数 ...
- 线性同余方程和中国剩余定理学习笔记
线性同余方程介绍 形如 a x ≡ c ( m o d b ) ax \equiv c \pmod b ax≡c(modb) 的方程被称为 线性同余方程(Congruence Equation). 求 ...
- ACM-ICPC模板整理
备注其一:正在整理中,内容不全,部分代码测试次数较少或还未在OJ上尝试,可能会有代码不健全的情况发生. 备注其二:部分图片来自百度百科.wiki百科. 备注其三:CSDN一天只能上传十篇blog... ...
- Codeforces 题目合集+分类+代码 【Updating...】【361 in total】
961A - Tetris 模拟 ...
- [Codeforces]Codeforces Round #460 (Div. 2)
Supermarket 找最便宜的就行 Solution Perfect Number 暴力做 Solution Seat Arrangement 注意当k=1时,横着和竖着是同一种方案 Soluti ...
- 2018中国大学生程序设计竞赛-网络选拔赛题解
以下所有AC题解程序来自"仙客传奇"团队. A. Buy and Resell AC的C++语言程序: #include<iostream> #include<c ...
- oracle求非偶非素数的和,Sub Maths__写给非数学专业的朋友们
[本文系寄托天下原创,转载请注明出处,拜托.] [综合版版主]GOGO ^^ 附4.GOGO的数学词汇 map image fixed point composite function one to ...
最新文章
- 分享mac磁盘清理的方法
- vim复制内容到系统剪贴板
- 清华大学计算机系71班张晨,“神仙打架”要来了!网友:又到了凡人围观的时刻...
- 最短路径(Shortest Paths)
- sysfs接口函数的建立_DEVICE_ATTR
- 【功能业务篇】APP获取用户定位、传参经纬度思考
- 深入了解帆软报表系统的启动过程二
- 对AUTOCAD软件的一些配置
- Fusion-IO:应用应为闪存优化
- qq手机令牌 for android3.3 官方安装版,原QQ安全助手|QQ手机管家 for Android 安卓版v3.3.0 - PC6安卓网...
- c语言谱曲软件,基于C语言的音乐谱曲技巧与应用研究
- fedora 11源码安装设置fcitx3.6输入法
- Java | Comparable接口和Comparator接口比较
- 十分钟了解绘图神器——Graphviz学习笔记
- JDK 8 之 Stream sorted() 示例
- 【Linux】Alibaba Cloud Linux 3 中第二硬盘、MySQL8.*、MySQL7.*、Redis、Nginx、Java 系统安装
- 什么是CF , correlation filer ? 【无标题】
- 虚拟机下载安装Centos7(新手详解)
- 三天让车跑起来!stm32循迹车 —— 第一天:基本模块使用方法
- User root is not allowed to impersonate anonymous
热门文章
- Linux系统管理--vim编辑器
- FileUpload 上传视频文件简单实例
- hosts文件的作用以及hosts中多个ip映射一个域名地址的解析顺序
- 怎么查电影备案? 中国电影查询官网、影剧备字查询系统
- HFSS入门学习(二)
- Dell inspiron 14 5000 series重装系统过程
- get请求400错误 vue_IE浏览器http请求,中文传参报400错误-解决方法
- 安装Office 2019
- 盗墓诡闻录服务器维护,幽行玄城摸金校尉职业厉不厉害 盗墓诡闻录摸金校尉技能解析...
- JavaScript数组的创建以及常用用法