Discrete Logarithm Problem

题目链接:

http://acm.hust.edu.cn/vjudge/contest/127401#problem/D

Description


http://7xjob4.com1.z0.glb.clouddn.com/42600d1bedc3c308a68ea0453befd84e

Input


The first line of the input file contains a prime p, 1

Output


For each test case, print out the solution x to the equation a
x = b in the finite group Zp. If there are no solutions, print ‘0’.

Sample Input


31
24 3
3 15
0

Sample Output


7
21


##题意:

求一个x使得 a^x%p = b .


##题解:

由于p的规模巨小(2^13),而取模的结果一定在p次以内出现循环,所以直接从0~p枚举x即可.
很多人TLE了,不知道什么姿势. (可能是末尾的0没有读好)
虽然是水题,还是很高兴拿了FB.


##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 1010
#define mod 100000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;

LL quickmod(LL a,LL b,LL m)

{

LL ans = 1;

while(b){

if(b&1){

ans = (ansa)%m;

b--;

}

b/=2;

a = a
a%m;

}

return ans;

}

int main(int argc, char const *argv[])

{

//IN;

int p; cin >> p;
LL a, b;
while(scanf("%lld", &a) != EOF && a)
{
scanf("%lld", &b);
a %= p; //b %= p; int ans = 0;
for(int i=0; i<=p+1; i++) {
if(quickmod(a, i, p) == b) {
ans = i;
break;
}
} printf("%d\n", ans);
} return 0;

}

UVALive 7457 Discrete Logarithm Problem (暴力枚举)的更多相关文章

  1. UVaLive 7457 Discrete Logarithm Problem (暴力)

    题意:求一个x使得 a^x%p = b p为素数: 析:从1开始扫一下就好,扫到p-1就可以了,关键是这个题为什么要用文件尾结束,明明说是0,但是不写就WA... 代码如下: #pragma comm ...

  2. 证明与计算(2): 离散对数问题(Discrete logarithm Problem, DLP)

    离散对数问题,英文是Discrete logarithm Problem,有时候简写为Discrete log,该问题是十几个开放数学问题(Open Problems in Mathematics, ...

  3. 2019杭电多校第五场 discrete logarithm problem

    https://vjudge.net/contest/317493#problem/I

  4. Gym 101194L / UVALive 7908 - World Cup - [三进制状压暴力枚举][2016 EC-Final Problem L]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

  5. HDU 3699 A hard Aoshu Problem(暴力枚举)(2010 Asia Fuzhou Regional Contest)

    Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...

  6. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  7. HNU 12886 Cracking the Safe(暴力枚举)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...

  8. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  9. bzoj 1028 暴力枚举判断

    昨天梦到这道题了,所以一定要A掉(其实梦到了3道,有两道记不清了) 暴力枚举等的是哪张牌,将是哪张牌,然后贪心的判断就行了. 对于一个状态判断是否为胡牌,1-n扫一遍,然后对于每个牌,先mod 3, ...

随机推荐

  1. Ios tab Bar 使用方法

    http://blog.sina.com.cn/s/blog_63578f140100w56m.html UITabBar* tabBar = [[UITabBar alloc] initWithFr ...

  2. input默认提示取消

    input 输入框有提示功能,当你之前输入过一些内容,你下次打入相关字符的时候,默认会有之前输入的一些相关的字符的提示,这个提示一般来说还是很好的,但是,有时候,我们想自己输入,不想要提示. 如果不需 ...

  3. chrome调试、移动端调试

    chrome 32版本后,添加 DevTools for Mobile 插件就可远程手机调试 DevTools for Mobile插件安装https://support.google.com/chr ...

  4. linux/unix网络编程之 select

    转自http://www.cnblogs.com/zhuwbox/p/4221934.html linux 下的 select 知识点 unp 的第六章已经描述的很清楚,我们这里简单的说下 selec ...

  5. c++ 完成端口资料

    文章地址: http://blog.csdn.net/piggyxp/article/details/6922277 附件如下: word文档 PiggyIOCPServer_2008.rar Pig ...

  6. LeetCode中有技巧的题需要面试前记得的

    https://leetcode.com/problems/insert-interval/ http://www.cnblogs.com/yxzfscg/p/4459173.html https:/ ...

  7. Informatica元数据库解析

    Informatica所有的元数据信息均以数据库表的方式存到了元数据库中.当然Infa本身工具提供了很多的人性化的功能,使我们在开发时可以很方便的进行操作,但人们的需求总是万变的,需要方便的取到自己需 ...

  8. sharepoint SPFolder的使用

    转:http://blog.csdn.net/pclzr/article/details/7591731 SPFolder是SharePoint对象模型中文件夹相关的类,它的使用方法相对比较简单.获取 ...

  9. Top Android App使用的组件 3

    8684公交 AdChina:com.adchina:易传媒广告平台 AdsMogo:com.adsmogo:芒果移动广告平台 大姨吗 AChartEngine:org.achartengine:An ...

  10. CMake实践(2)

    一,本期目标: [~@localhost t2]$ cat README this is README├── CMakeLists.txt├── COPYRIGHT├── doc│   └── hel ...