bzoj 1467: Pku3243 clever Y 扩展BSGS
1467: Pku3243 clever Y
Time Limit: 4 Sec Memory Limit: 64 MB
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
2 4 3
0 0 0
Sample Output
No Solution
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
const int MAXN= ;
struct LINK{
ll data;
ll j;
ll next;
}HASH_LINK[];
ll ad, head[MAXN]; ll Gcd(ll a, ll b){
return b ? Gcd(b, a % b) : a;
} ll Ext_Gcd(ll a, ll b, ll &x, ll &y){
if(!b){
x = ; y = ;
return a;
}
ll r = Ext_Gcd(b, a % b, x, y);
ll t = x; x = y; y = t - a / b * y;
return r;
} ll POWER(ll a, ll b, ll c){
ll ans = ;
while(b){
if(b & ) ans = ans * a % c;
a = a * a % c;
b >>= ;
}
return ans;
} void init(){
memset(head, -, sizeof(head));
ad = ;
} ll Hash(ll a){
return a % MAXN;
} void INSERT_HASH(ll i, ll buf){
ll hs = Hash(buf), tail;
for(tail = head[hs]; ~tail; tail = HASH_LINK[tail]. next)
if(buf == HASH_LINK[tail]. data) return;
HASH_LINK[ad]. data = buf;
HASH_LINK[ad]. j = i;
HASH_LINK[ad]. next = head[hs];
head[hs] = ad ++;
} ll BSGS(ll a, ll b, ll c){
ll i, buf, m, temp, g, D, x, y, n = ;
for(i = , buf = ; i < ; i ++, buf = buf * a % c)
if(buf == b) return i;
D = ;
while((g = Gcd(a, c)) != ){
if(b % g) return -; // g | b 不满足,则说明无解
b /= g;
c /= g;
D = D * a / g % c;
++ n;
}
init();
m = ceil(sqrt((long double) c));
for(i = , buf = ; i <= m; buf = buf * a % c, i ++) INSERT_HASH(i, buf);
for(i = , temp = POWER(a, m, c), buf = D; i <= m; i ++, buf = temp * buf % c){
Ext_Gcd(buf, c, x, y);
x = ((x * b) % c + c) % c;
for(ll tail = head[Hash(x)]; ~tail; tail = HASH_LINK[tail].next)
if(HASH_LINK[tail]. data == x) return HASH_LINK[tail].j + n + i * m;
}
return -;
}
int main()
{
ll a,b,n;
while(~scanf("%lld%lld%lld",&a,&n,&b))
{
if(a==&&b==&&n==)break;
if(n<b)
{
printf("No Solution\n");
continue;
}
ll ans=BSGS(a,b,n);
if(ans==-)
printf("No Solution\n");
else
printf("%lld\n",ans%mod);
}
return ;
}
bzoj 1467: Pku3243 clever Y 扩展BSGS的更多相关文章
- poj 3243 Clever Y && 1467: Pku3243 clever Y【扩展BSGS】
扩展BSGS的板子 对于gcd(a,p)>1的情况 即扩展BSGS 把式子变成等式的形式: \( a^x+yp=b \) 设 \( g=gcd(a,p) \) 那么两边同时除以g就会变成: \( ...
- POJ 3243 Clever Y 扩展BSGS
http://poj.org/problem?id=3243 这道题的输入数据输入后需要将a和b都%p https://blog.csdn.net/zzkksunboy/article/details ...
- poj3243 Clever Y[扩展BSGS]
Clever Y Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 8666 Accepted: 2155 Descript ...
- bzoj1467 Pku3243 clever Y
1467: Pku3243 clever Y Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 313 Solved: 181[Submit][Status ...
- 【EX_BSGS】BZOJ1467 Pku3243 clever Y
1467: Pku3243 clever Y Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 425 Solved: 238[Submit][Status ...
- 【BZOJ1467/2480】Pku3243 clever Y/Spoj3105 Mod EXBSGS
[BZOJ1467/2480]Pku3243 clever Y/Spoj3105 Mod Description 已知数a,p,b,求满足a^x≡b(mod p)的最小自然数x. Input ...
- 【POJ 3243】Clever Y 拓展BSGS
调了一周,我真制杖,,, 各种初始化没有设为1,,,我当时到底在想什么??? 拓展BSGS,这是zky学长讲课的课件截屏: 是不是简单易懂.PS:聪哥说“拓展BSGS是偏题,省选不会考,信我没错”,那 ...
- [拓展Bsgs] Clever - Y
题目链接 Clever - Y 题意 有同余方程 \(X^Y \equiv K\ (mod\ Z)\),给定\(X\),\(Z\),\(K\),求\(Y\). 解法 如题,是拓展 \(Bsgs\) 板 ...
- bzoj 3283 扩展BSGS + 快速阶乘
T2 扩展BSGS T3 快速阶乘 给定整数n,质数p和正整数c,求整数s和b,满足n! / pb = s mod pc 考虑每次取出floor(n/p)个p因子,然后将问题转化为子问题. /*** ...
随机推荐
- 我是如何对网站CSS进行架构的
by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/wordpress/?p=944 一.写在前面的 ...
- linux设备驱动归纳总结(八):3.设备管理的分层与面向对象思想【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-110738.html linux设备驱动归纳总结(八):3.设备管理的分层与面向对象思想 xxxxxx ...
- 空格和TAB键混用错误:IndentationError: unindent does not match any outer indentation level
转自:http://www.crifan.com/python_syntax_error_indentationerror/comment-page-1/ [已解决]Python脚本运行出现语法错误: ...
- iOS原生JSON解析.
- (IBAction)accessInterfaceBtnPressed:(id)sender { NSError *error; NSString *URL=@"ht ...
- 学习Perl6: slice fastq file
需求: 只获取 ath 物种的 hairpin 序列 文件格式如下所示,以>打头的为 header,紧跟的为序列[AUCG]+ (Perl5 regexp 格式) #!/usr/bin/env ...
- win7中搜索文件内容的方法
打开“控制面板”,选择“大类别”或“小类别”,然后打开 “索引选项”.点击“高级”按钮,在弹出的对话框中打开“文件类型”标签,在下方的输入框中“将新扩展名添加到列表中”,添加要搜索的未知文本文件的扩展 ...
- Docker 端口映射问题解决
在操作Docker容器时发现了其一个端口映射的BUG,具体表现为:开启容器时做了端口映射80:8080,即宿主机的80端口映射到容器内部的8080Jboss端口.一开始测试也没有什么问题,都可以联通, ...
- Shipyard安装、使用
Shipyard使用Citadel集群管理工具包,简化对横跨多个主机的Docker容器集群进行管理.通过Web用户界面,你可以大致浏览相关信息,比如你的容器在使用多少处理器和内存资源.在运行哪些容器, ...
- 解决HP服务器安装Centos7 x64无法识别硬盘
公司有一台老旧的HP服务器——HP BL460c G7 SmartArray P410i.由于种种原因,需要重新安装操作系统Centos7.但是经过各种努力,Centos7的安装程序就是无法识别服务器 ...
- vsftpd
vi /etc/vsftpd.conf and add the following allow_writeable_chroot=YES sudo service vsftpd restart