UVALive 7457 Discrete Logarithm Problem
来源:互联网 发布:jquery.jsoncookie.js 编辑:程序博客网 时间:2024/06/16 07:14
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5479
题意:给出a,b,p。求( a ^ x ) % p = b中的x。
思路:由于p不超过1W,那么%p后的答案也是小于p的,所以我们乘1W次如果能找到符合条件的x,那么就是存在的;否则无解。
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <cstdlib>#include <iostream>#include <algorithm>#include <stack>#include <map>#include <set>#include <vector>#include <sstream>#include <queue>#include <utility>using namespace std;#define rep(i,j,k) for (int i=j;i<=k;i++)#define Rrep(i,j,k) for (int i=j;i>=k;i--)#define Clean(x,y) memset(x,y,sizeof(x))#define LL long long#define ULL unsigned long long#define inf 0x7fffffff#define mod 100000007const int maxn = 10009;int p;int a,b;int main(){ cin>>p; while( scanf("%d%d",&a,&b) == 2 ) { if ( b == 1 ) { puts("0"); continue; } int ans = 0; int temp = 1; bool f = false; rep(i,1,maxn) { ans++; temp = ( temp * a ) % p; if ( temp == b ) { f = true; printf("%d\n",ans); break; } } if ( !f ) puts("0"); } return 0;}
0 0
- UVALive 7457 Discrete Logarithm Problem
- LA 7457 Discrete Logarithm Problem
- UVALive Problem 7457 Discrete Logarithm Problem——Regionals 2015 :: Asia - Taipei
- 数学 ( 解高次同余方程 )——Discrete Logarithm Problem ( UVA 7457 )
- LA 7457 Discrete Logarithm Problem(shank的大步小布算法)
- Discrete Problem 14
- Discrete Problem 13
- UVALive 4270 Discrete Square Roots 模方程,数论
- [51nod1150] Logarithm
- [51nod1150]Logarithm
- UVALive 5861 Hidden Terminal Problem 解题报告
- UVALive 6198 A Terribly Grimm Problem
- Amritapuri 2009 (UValive 4676 ) - Geometry Problem
- UVALive - 7271 A Math Problem (hihocoder 1259)
- UVALive-3683 A Scheduling Problem(treedp)
- Problem on Group Trip UVALive - 7219
- THE MATRIX PROBLEM HDU 3666 UVALive
- [UVALive 6696] A Generalized N-Queens Problem
- lua倒序删除数据
- 前端网站优化
- 个人笔记
- Mac安装VM虚拟机
- 文件系统之FastDFS
- UVALive 7457 Discrete Logarithm Problem
- 用c++程序向百度apistore中发送消息获得天气等信息
- activity间跳转简单方式
- 简单强大的Android内存泄漏检测工具 LeakCanary
- error C4703: 使用了可能未初始化的本地指针变量“db”
- Android Studio中改变字体大小
- React Native之React速学教程(下)
- C++学习2
- hash解决冲突之---平方探测