题目大意:给出$P,B,N$,求最小的正整数$L$,使$B^L\equiv N(mod\ P)$。

$BSGS$模板题。

#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int T,k;
ll y,z,p;
ll G;
map<ll,int>ind;
ll quick(ll x,ll y,ll mod)
{
ll res=1ll;
while(y)
{
if(y&1)
{
res=res*x%mod;
}
x=x*x%mod;
y>>=1;
}
return res;
}
void solve()
{
ll n=ceil(sqrt(p));
if(y%p==0&&z)
{
printf("no solution\n");
return ;
}
ind.clear();
ll sum=z%p;
ind[sum]=0;
for(ll i=1;i<=n;i++)
{
sum=sum*y;
sum%=p;
ind[sum]=i;
}
sum=quick(y,n,p);
ll num=1ll;
for(int i=1;i<=n;i++)
{
num*=sum,num%=p;
if(ind.find(num)!=ind.end())
{
printf("%lld\n",((n*i-ind[num])%p+p)%p);
return ;
}
}
printf("no solution\n");
}
int main()
{
while(scanf("%lld%lld%lld",&p,&y,&z)!=EOF)
{
solve();
}
}

BZOJ3239Discrete Logging——BSGS的更多相关文章

  1. BZOJ 3239--Discrete Logging(BSGS)

    3239: Discrete Logging Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 635  Solved: 413[Submit][Statu ...

  2. 【BZOJ3239】Discrete Logging BSGS

    [BZOJ3239]Discrete Logging Description Given a prime P, 2 <= P < 231, an integer B, 2 <= B ...

  3. POJ 2417 Discrete Logging BSGS

    http://poj.org/problem?id=2417 BSGS 大步小步法( baby step giant step ) sqrt( p )的复杂度求出 ( a^x ) % p = b % ...

  4. poj2417 Discrete Logging BSGS裸题

    给a^x == b (mod c)求满足的最小正整数x, 用BSGS求,令m=ceil(sqrt(m)),x=im-j,那么a^(im)=ba^j%p;, 我们先枚举j求出所有的ba^j%p,1< ...

  5. 【BSGS】BZOJ3239 Discrete Logging

    3239: Discrete Logging Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 729  Solved: 485[Submit][Statu ...

  6. BSGS算法+逆元 POJ 2417 Discrete Logging

    POJ 2417 Discrete Logging Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4860   Accept ...

  7. POJ2417 Discrete Logging【BSGS】

    Discrete Logging Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5577   Accepted: 2494 ...

  8. BSGS 扩展大步小步法解决离散对数问题 (BZOJ 3239: Discrete Logging// 2480: Spoj3105 Mod)

    我先转为敬? orz% miskcoo 贴板子 BZOJ 3239: Discrete Logging//2480: Spoj3105 Mod(两道题输入不同,我这里只贴了3239的代码) CODE ...

  9. POJ-2417-Discrete Logging(BSGS)

    Given a prime P, 2 <= P < 2 31, an integer B, 2 <= B < P, and an integer N, 1 <= N &l ...

随机推荐

  1. R实战 第十二篇:随机数

    由R生成的随机数实际上伪随机数,也就是说,随机数是由某种算法而不是真正的随机过程产生的,随机数生成器需要一个初始值来生成数字,该初始值叫做种子.通过把种子设置为特定的值,可以保证每次运行同一段代码时都 ...

  2. JVM总括:目录

    JVM总括:目录 JVM总括一-JVM内存模型 JVM总括二-垃圾回收:GC Roots.回收算法.回收器 JVM总括三-字节码.字节码指令.JIT编译执行 JVM总括四-类加载过程.双亲委派模型.对 ...

  3. Angular下载文件

    public Down(path: string) { return this.http.get(path, { responseType: "blob" }).subscribe ...

  4. 配置linux-Fedora系统下iptables防火墙

    参考地址:https://blog.csdn.net/zhangjingyi111/article/details/78902820 本篇文章为实验课过程记录,较为简略. 1.查看系统是否安装ipta ...

  5. PHP实用代码片段(四)

    1. 删除文件夹内容 function Delete($path) { if (is_dir($path) === true) { $files = array_diff(scandir($path) ...

  6. python获取当前日期时间

    转载自:https://www.cnblogs.com/wenBlog/p/6023742.html 在Python里如何获取当前的日期和时间呢?在Python语言里,我们可以通过调用什么模块或者类函 ...

  7. PAT L2-023 图着色问题

    https://pintia.cn/problem-sets/994805046380707840/problems/994805057298481152 图着色问题是一个著名的NP完全问题.给定无向 ...

  8. Docker Compose vs. Dockerfile

    Docker Compose vs. Dockerfile - which is better? - Stack Overflowhttps://stackoverflow.com/questions ...

  9. LINUX操作系统(centos6.9)安装与配置

    LINUX操作系统(centos6.9)安装与配置_百度经验 https://jingyan.baidu.com/article/acf728fd6bdba1f8e510a3f7.html cento ...

  10. b,B,KB,MB,GB,TB,PB,EB,ZB,YB,BB,NB,DB的含义,之间的关系

    1bit=1位2进制信息 1B (byte 字节)1KB(Kilobyte 千字节)=2(10)B=1024B=2(10)B: 1MB(Megabyte 兆字节)=2(10)KB=1024KB=2(2 ...