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. Android XML使用的学习记录

    1. 注释其中一段代码或是一行,可以采用<!-- -->,示例如下 <!--       <EditText         android:layout_width=&quo ...

  2. rundeck email配置文件配置

    最近工作中用到了一个任务管理软件rundeck,其中有个很重要的功能就是任务执行提醒,用邮件执行,其中一些配置项,官网没有详细的说明,在网上也没有一个整体的说明,在次跟大家共享下,rundeck的使用 ...

  3. 一个简单json数据提交实例

    1.客户端编程:jsp页面 <%@ page language="java" contentType="text/html; charset=UTF-8" ...

  4. python 字符串换行的三种方式

    if __name__ == '__main__': #第一种: 三个单引号 print ''' aaaaaaaaaaaaaaaa         bbbbbbbbbbbbbb''' #第二种: 三个 ...

  5. [转]ASP.NET 页生命周期概述

    原文链接:http://msdn.microsoft.com/zh-cn/library/ms178472(v=vs.110).aspx  对应版本:.NET 4.0 ASP.NET 页运行时,此页将 ...

  6. php通过curl调用jpush接口实现消息的推送

    public function actionNotifyto() { //$regid = $_REQUEST['regid']; $url = 'https://api.jpush.cn/v3/pu ...

  7. hdu 5310 Souvenir (水)

    题意:今天是BestCoder一周年纪念日. 比赛管理员Soda想要给每个参赛者准备一个纪念品. 商店里纪念品的单价是p元, 同时也可以花q元购买纪念品套装, 一个套装里有m个纪念品.今天总共有n个参 ...

  8. c & c++中static的总结

    static 修饰的三种作用 (1) 静态局部变量 (2) 模块内的全局变量.函数,不可以被其他模块访问 (3) 类的静态成员 其中(3)只在c++中有. (1) 静态局部变量.局部变量一般在函数体内 ...

  9. ES PES TS

    1.流媒体系统结构 ES:elemental stream 基本数据流: PES:packet elemental stream分组的基本数据流: 然后把PES打包成PS ,TS流,PS:progra ...

  10. spring aop expression简单说明

    <aop:config> <aop:pointcut id="userDAO" expression="execution(public * cn.da ...