bzoj 3239: Discrete Logging BSGS
来源:互联网 发布:java表格代码怎么写 编辑:程序博客网 时间:2024/06/04 20:12
题意
给出b,p,n,求一个l,使得
分析
离散对数模板题,当复习一波。
思路是把l分块,然后扔进map里。
代码
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<map>#define LL long longusing namespace std;int p,b,n;map<int,int> w;int ksm(int x,int y){ int ans=1; while (y) { if (y&1) ans=(LL)ans*x%p; x=(LL)x*x%p;y>>=1; } return ans;}int solve(){ int ny=ksm(b,p-2),m=sqrt(p); w.clear(); int v=n;w[n]=-1; for (int i=1;i<m;i++) { v=(LL)v*ny%p; if (!w[v]) w[v]=i; } b=ksm(b,m);v=1; for (int i=0;i<=m;i++) { int x=w[v]; if (x) { if (x==-1) return i*m; else return i*m+x; } v=(LL)v*b%p; } return -1;}int main(){ while (scanf("%d%d%d",&p,&b,&n)!=EOF) { int ans=solve(); if (ans==-1) printf("no solution\n"); else printf("%d\n",ans); } return 0;}
0 0
- BZOJ 3239 Discrete Logging BSGS
- bzoj 3239: Discrete Logging BSGS
- BZOJ 3239 Discrete Logging BSGS
- bzoj 3239: Discrete Logging (BSGS)
- POJ 2417/BZOJ 3239(Discrete Logging-BSGS)[Template:数论]
- 【bzoj 3239】【POJ 2417】Discrete Logging(BSGS)
- 【BZOJ】【P3239】【Discrete Logging】【题解】【BSGS】
- 【BZOJ 3239】 Discrete Logging
- bzoj-3239 Discrete Logging
- 【bzoj3239】Discrete Logging BSGS
- [BZOJ3239][BSGS]Discrete Logging
- BZOJ-2995&&2480&&3239 同余方程&Mod&Discrete Logging 拓展BSGS算法
- POJ 2417 Discrete Logging BSGS
- [POJ 2417]Discrete Logging:BSGS
- [poj 2417]Discrete Logging 数论 BSGS
- [poj 2417] Discrete Logging · BSGS
- [BZOJ3239][poj2417]Discrete Logging(BSGS算法)
- Bzoj3239:Discrete Logging:BSGS模板题
- xpath登陆案例
- python超级简单爬虫
- Hibernate中的Criteria的投影和条件查询和排序和分页
- 【九度OJ】题目1173:查找 解题报告
- Hive常用的SQL命令操作
- bzoj 3239: Discrete Logging BSGS
- 【Codeforces 140 A. New Year Table】 + 精度
- 文章标题
- iOS 打包时出现在other items
- 梦想起航
- Linux系统下的常用命令
- robot framework读取Excel文件,并保存为list
- RatingBar流泪、有脚、显示不全问题
- (C++基础)浅谈继承与派生