题目大意:给出$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. 你不知道的腾讯社招面试经验(已offer)

    # 你不知道的腾讯社招面试经验(已offer) ## 背景 最近一段时间换工作,成功获得了腾讯的offer.在这里有点经验跟大家分享,我觉得,比起具体的面试题,有些东西更加重要,你知道这些东西,再去准 ...

  2. 协程 IO多路复用

    -----------------------------------------------------------------试试并非受罪,问问并不吃亏.善于发问的人,知识丰富. # # ---- ...

  3. 剑指offer--3.从头打印链表

    题目:输入一个链表,按链表值从尾到头的顺序返回一个ArrayList. 思路:可以利用push 和unshift /*function ListNode(x){ this.val = x; this. ...

  4. 617. Merge Two Binary Trees(Easy)

    Given two binary trees and imagine that when you put one of them to cover the other, some nodes of t ...

  5. Selenium库

    '''自动化测试工具,支持多种浏览器.爬虫中主要用来解决JavaScrip渲染的问题.''''''基本使用'''from selenium import webdriverfrom selenium. ...

  6. rest-framework总结

    1. CBV: pass 2 .APIView class BookView(APIView):pass url(r'^books/$', views.BookView.as_view(),name= ...

  7. PHP中多个文件包含的问题 (一)

    使用require或者include来包含文件时,包含的文件的内容相对性,这个很容易搞混,所以记录一下. 这个相对性包括 __DIR__,__FILE__,$_SERVER['PHP_SELF'],$ ...

  8. PAT L3-010 是否完全二叉搜索树

    https://pintia.cn/problem-sets/994805046380707840/problems/994805049870368768 将一系列给定数字顺序插入一个初始为空的二叉搜 ...

  9. 使用Random类生成指定范围的随机数

    目的:要生成在[min,max]之间的随机整数 public class RandomTest { public static void main(String[] args) { ; ; Rando ...

  10. Eclipse的智能提示的设置

    智能提示修改方式是: Windows——>Preferences——>Java-->Editor-->Content Asist,在Auto activation trigge ...