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 ...
随机推荐
- B. Secret Combination
B. Secret Combination time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Ubuntu下 jdk环境变量设置
流程 1. 官网下载对应的jdk文件 2. 在根目录 / 下创建一个java目录 mkdir /java 3. 使用mv命令 将下载下来的文件(压缩格式),移动到上一步创建的/java目录下 Ps ...
- 迈向c++的一次尝试
从C到C++说着容易做起来也不难,今天做一下尝试. ★:题目介绍:今天是一次尝试所以先从简单的题开始. ★:试题分析:由题可了解到本题目的是要做到由一个数字到一个字符串的转变. 题目简单是由于它只是让 ...
- 学习Lucene、solr之前应当了解的一些术语
一些简单易理解术语,例如:词条搜索.语义信息.搜索引擎 搜索引擎分类:全文搜索(百度.谷歌).目录搜索.元搜索.垂直搜索 元搜索例子:360综合搜索.搜魅网(someta 集合了百度.google.搜 ...
- 关于JWPlayer播放器的一些测试学习
<!DOCTYPE html><html><head> <title>jwplayer播放器测试</title> <script ty ...
- JavaScript实现Tab栏切换
本文最初发表于博客园,并在GitHub上持续更新前端的系列文章.欢迎在GitHub上关注我,一起入门和进阶前端. 以下是正文. 京东网页上,可以看到下面这种tab栏的切换: 我们把模型抽象出来,实现一 ...
- MySQL时间差返回月个数
select PERIOD_DIFF(date_format(now(),'%Y%m'),date_format('2010-11-30','%Y%m')) 1. MySQL 为日期增加一个时间间隔: ...
- php等比例压缩图片
<?php function resizeImage($im,$maxwidth,$maxheight,$name,$filetype) { $pic_width = imagesx($im); ...
- Hystrix请求命令 HystrixCommand、HystrixObservableCommand
Hystrix有两个请求命令 HystrixCommand.HystrixObservableCommand. HystrixCommand用在依赖服务返回单个操作结果的时候.又两种执行方式 -ex ...
- 安装python的注意事项
第一步: 下载安装文件 python-3.5.2.exe 第二步: 点击安装,下一步继续 第三步: 配置环境变量,记住第一次安装时的路径. 第四步: 测试,打开CMD,输入python.若未找到命令 ...