BZOJ 3239: Discrete Logging [BGSG]
裸题
求\(ind_{n,a}b\),也就是\(a^x \equiv b \pmod n\)
注意这里开根不能直接下取整
这个题少了一些特判也可以过...
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
const double PI=acos(-1);
inline int read(){
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
int a, b, n;
map<int, int> ma;
int Pow(ll a, int b, int p) {
ll ans=1;
for(; b; b>>=1, a=a*a%p)
if(b&1) ans=ans*a%p;
return ans;
}
int ind(int n, int a, int b) {
int m=ceil(sqrt(n)+1e-8);
ma.clear();
int e=1;
for(int i=0; i<m; i++) {
if(!ma.count(e)) ma[e]=i;
e=(ll)e*a%n;
}
e=Pow(e, n-2, n);
for(int i=0; i<m; i++) {
if(ma.count(b)) return i*m + ma[b];
b=(ll)b*e%n;
}
return -1;
}
int main() {
freopen("in","r",stdin);
while(scanf("%d%d%d",&n,&a,&b)!=EOF) {
int x = ind(n, a, b);
if(x==-1) puts("no solution");
else printf("%d\n",x);
}
}
BZOJ 3239: Discrete Logging [BGSG]的更多相关文章
- BSGS 扩展大步小步法解决离散对数问题 (BZOJ 3239: Discrete Logging// 2480: Spoj3105 Mod)
我先转为敬? orz% miskcoo 贴板子 BZOJ 3239: Discrete Logging//2480: Spoj3105 Mod(两道题输入不同,我这里只贴了3239的代码) CODE ...
- BZOJ 3239 Discrete Logging(BSGS)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3239 [题目大意] 计算满足 Y^x ≡ Z ( mod P) 的最小非负整数 [题解 ...
- bzoj 3239: Discrete Logging && 2480: Spoj3105 Mod【BSGS】
都是BSGS的板子题 此时 \( 0 \leq x \leq p-1 \) 设 \( m=\left \lceil \sqrt{p} \right \rceil ,x=i*m-j \)这里-的作用是避 ...
- 【BZOJ】3239: Discrete Logging
http://www.lydsy.com/JudgeOnline/problem.php?id=3239 题意:原题很清楚了= = #include <bits/stdc++.h> usi ...
- 【BSGS】BZOJ3239 Discrete Logging
3239: Discrete Logging Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 729 Solved: 485[Submit][Statu ...
- 【BZOJ】【3239】Discrete Logging
BSGS BSGS裸题,嗯题目中也有提示:求a^m (mod p)的逆元可用快速幂,即 pow(a,P-m-1,P) * (a^m) = 1 (mod p) /******************** ...
- poj 2417 Discrete Logging ---高次同余第一种类型。babystep_gaint_step
Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2831 Accepted: 1391 ...
- BSGS算法+逆元 POJ 2417 Discrete Logging
POJ 2417 Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4860 Accept ...
- POJ 2417 Discrete Logging (Baby-Step Giant-Step)
Discrete Logging Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2819 Accepted: 1386 ...
随机推荐
- angular2 Http和websocket
1. 注入HttpModule模块: 2. 注入http服务 map方法需要导入"rajx/Rx"组件,作用是针对流的处理.Json是将流转化为json格式.subscribe订阅 ...
- React Native学习(六)—— 轮播图
本文基于React Native 0.52 Demo上传到Git了,有需要可以看看,写了新内容会上传的.Git地址 https://github.com/gingerJY/React-Native-D ...
- 浅谈event.client、event.screen与event.offset
每每看到event.client.event.screen与event.offset这几个,头都大了,今天又碰到了,特来总结下. 1.event.screenX与event.screenY. 首先,e ...
- 全国银行列表json格式
var list=[ { value:'CDB', text:'国家开发银行' }, { value:'ICBC', text:'中国工商银行' }, { value:'ABC', text:'中国农 ...
- linux一键安装
http://source.docs.cloudcare.cn/support/faq/webfaq/webfaq_11/?spm=5176.730006-cmgj000262.102.8.QsmPR ...
- JavaScript常见封装方法
1.最简单的,使用变量,然后用匿名函数包裹,不封装 2.对象字面量简单封装(不完整的模块模式,因为无法达到变量.方法私有效果.不过确实有分离和组织代码的能力,也就算一种简略的模块模式的实现方式) va ...
- HttpServletRequest cannot be resolved to a type。
问题描述:HttpServletRequest cannot be resolved to a type.Multiple markers at this line - The import java ...
- 百度Apollo 尝试
从Git-Hub上下载了Apollo源码在Ubuntu上准备运行一下 完成了以下步骤: bash docker/scripts/install_docker.sh bash docker/script ...
- mybatis实战教程二:多对一关联查询(一对多)
多对一关联查询 一.数据库关系.article表和user表示多对一的关系 CREATE TABLE `article` ( `id` ) NOT NULL AUTO_INCREMENT, `user ...
- web、pc、wap、app的区别
通常情况下web=pc,wap=app,前者指电脑用的程序,后者指手机用的程序. 更深层的区别是,pc电脑上软件,web电脑上的网页,wap手机上的网页,app手机用软件