/**************************************************************
Problem: 3285
User: idy002
Language: C++
Result: Accepted
Time:756 ms
Memory:32072 kb
****************************************************************/ #include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#define N 1000010 typedef long long dnt; const int Hmod = ;
struct Hash {
int head[N], key[N], val[N], next[N], etot;
void init() {
etot = ;
memset( head, , sizeof(head) );
}
void insert( int k, int v ) {
int kk = k%Hmod;
etot++;
key[etot] = k;
val[etot] = v;
next[etot] = head[kk];
head[kk] = etot;
}
int query( int k ) {
int kk = k%Hmod;
for( int t=head[kk]; t; t=next[t] )
if( key[t]==k ) return val[t];
return -;
}
}hash; dnt mpow( dnt a, int b, int c ) {
dnt rt;
for( rt=; b; b>>=,a=(a*a)%c )
if( b& ) rt=(rt*a)%c;
return rt;
}
int findroot( int p ) {
int phi = p-;
int tmp = phi;
int stk[], top;
top = ;
for( int i=; i<=(<<); i++ ) {
if( tmp%i== ) {
stk[++top] = i;
do {
tmp/=i;
}while( tmp%i== );
}
}
if( tmp!= )
stk[++top] = tmp;
for( int r=; ; r++ ) {
bool ok = true;
for( int i=; i<=top; i++ ) {
if( mpow(r,phi/stk[i],p)== ) {
ok=false;
break;
}
}
if( ok ) return r;
}
}
dnt ind( dnt r, int a, int p ) { // ind_r(a) mod p-1
int m = ceil(sqrt(p-));
hash.init();
dnt cur = ;
for( int i=; i<m; i++ ) {
if( cur==a ) return i;
hash.insert( cur, i );
cur = (cur*r) % p;
}
dnt base;
base = cur = mpow(cur,p-,p);
for( int i=m; i<p; i+=m,cur=(cur*base)%p ) {
int j = hash.query( a*cur%p );
if( j!=- ) return i+j;
}
return -; // impossible
}
dnt gcd( dnt a, dnt b ) {
return b ? gcd(b,a%b) : a;
}
void exgcd( dnt a, dnt b, dnt &d, dnt &x, dnt &y ) {
if( b== ) {
d=a, x=, y=;
} else {
exgcd(b,a%b,d,y,x);
y-=a/b*x;
}
}
dnt meq( dnt a, dnt b, dnt c ) { // ax=b mod c
dnt d, dd, x, y;
a = (a%c+c)%c;
b = (b%c+c)%c;
d = gcd(a,c);
if( b%d!= ) return -;
exgcd(a/d,c/d,dd,x,y);
x = x*(b/d);
x = (x%(c/d)+(c/d))%(c/d);
if( x== ) x+=c/d;
return x;
} dnt a, b, c, g, p, r;
int aa[N], bb[N], cc[N], gg[N]; void read( int a[] ) {
int i;
char ch;
for( i=; isdigit(ch=getchar()); i++ )
a[i] = ch-'';
a[i] = -;
}
dnt modulo( int a[], dnt mod ) {
dnt rt = ;
for( int i=; a[i]!=-; i++ )
rt = (rt* + a[i]) % mod;
return rt;
}
int main() {
read(aa);
read(bb);
read(cc);
read(gg);
scanf( "%lld", &p );
a = modulo(aa,p-);
b = modulo(bb,p-),
c = modulo(cc,p);
g = modulo(gg,p); if( g%p== || c%p== ) {
if( g%p== && c%p== )
printf( "1\n" );
else
printf( "no solution\n" );
return ;
}
r = findroot(p);
// fprintf( stderr, "%d\n", (int)r );
dnt ans = meq( a*ind(r,g,p), ind(r,c,p)-b*ind(r,g,p), p- );
if( ans< )
printf( "no solution\n" );
else
printf( "%lld\n", ans );
}

bzoj 3285 离散对数解指数方程的更多相关文章

  1. bzoj 3751: [NOIP2014]解方程 同余系枚举

    3.解方程(equation.cpp/c/pas)[问题描述]已知多项式方程:a ! + a ! x + a ! x ! + ⋯ + a ! x ! = 0求这个方程在[1, m]内的整数解(n 和 ...

  2. 牛顿迭代法解指数方程(aX + e^x解 = b )

    高中好友突然问我一道这样的问题,似乎是因为他们专业要做一个计算器,其中的一道习题是要求计算器实现这样的功能. 整理一下要求:解aX + e^X = b 方程.解方程精度要求0.01,给定方程只有一解, ...

  3. bzoj 3751: [NOIP2014]解方程

    Description 已知多项式方程: a0+a1x+a2x^2+...+an*x^n=0 求这个方程在[1,m]内的整数解(n和m均为正整数). 解题报告: 这题比较诡,看到高精度做不了,就要想到 ...

  4. BZOJ 3751: [NOIP2014]解方程 数学

    3751: [NOIP2014]解方程 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=3751 Description 已知多项式方程: ...

  5. bzoj 3751: [NOIP2014]解方程【数学】

    --我真是太非了,自己搞了7个质数都WA,从别人那粘5个质数就A了-- 就是直接枚举解,用裴蜀定理计算是否符合要求,因为这里显然结果很大,所以我们对多个质数取模看最后是不是都为0 #include&l ...

  6. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  7. bzoj 2654 && bzoj 3675 总结

    手动博客搬家: 本文发表于20180929 15:18:55, 原地址https://blog.csdn.net/suncongbo/article/details/82897992 最近做到了两道( ...

  8. bzoj1644 / P1649 [USACO07OCT]障碍路线Obstacle Course

    P1649 [USACO07OCT]障碍路线Obstacle Course bfs 直接上个bfs 注意luogu的题目和bzoj有不同(bzoj保证有解,还有输入格式不同). #include< ...

  9. BZOJ4869:[SHOI2017]相逢是问候——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=4869 题面复制于洛谷:https://www.luogu.org/problemnew/show/P ...

随机推荐

  1. bzoj千题计划253:bzoj2154: Crash的数字表格

    http://www.lydsy.com/JudgeOnline/problem.php?id=2154 #include<cstdio> #include<algorithm> ...

  2. Linux之svn数据备份、还原及迁移

    前言 因管理需求现要将svn数据进行备份,作为运维小哥的我在收到指令后进行了相关操作.当然,领导告知的是要备份,但作为一个有思想的运维,我考虑到的是自己要干的不仅仅是备份操作,还要确保在备份后数据还原 ...

  3. 开启SSI配置使shtml支持include公用的页头页脚

    编写编写项目众多静态文件时,能像php等开发语言一样使用include将页面公有的header/footer/sidebar作为公用.独立.单一的文件引入到各页面上,这样修改这些页面公用部分时就能单独 ...

  4. Angular 下的 directive (part 2)

    ngCloak ngCloak指令被使用在,阻止angular模板从浏览器加载的时候出现闪烁的时候.使用它可以避免闪烁问题的出现.   该指令可以应用于<body>元素,但首选使用多个ng ...

  5. Guava HashMultiMap(MultiMap)反转映射

    (一)MultiMap 多重map,一个key可以对应多个值(多个值放在一个list中),可用于分组 举例: Multimap<String, Integer> map = HashMul ...

  6. 如何对xilinx FPGA进行bit文件加密

    记录背景:最近在用Vivado评估国外一个公司所提供的ISE所建的工程时,由于我并没有安装ISE工程,因此将其提供的所有v文件导入到Vivado中,对其进行编译.添加完之后成功建立顶层文件,但奇怪的是 ...

  7. 高可用的并行MySQL数据同步及分布式

    首先聊聊MySQL的数据分布式,目前最为常用的就是Replication(复制)技术.基于此技术外延开来有很多中架构,分类归结为如下:      1.树状结构(Master,Backup-Master ...

  8. php中数据库连接方式pdo和mysqli对比分析

    1)总的比较   PDO MySQLi 数据库支持 12种不同的数据库支持 支持MySQL API OOP OOP + 过程 Connection Easy Easy 命名参数 支持 不支持 对象映射 ...

  9. 常用RAID级别的介绍

    随时科技的进步,各种各样的技术也层出不穷,当然RAID的组合也一样,嘻嘻,下面跟大家一起来学习下常用的RAID RAID的全称廉价磁盘冗余阵列(Redundant Array of Inexpensi ...

  10. plaidctf-2016 Pwn试题小结

    回顾了一下今年plaidctf Pwn部分的题目,感觉还是蛮有意思的,值得研究一下. 1.unix_time_formatter-76 最简单的一道题,考点是UAF.说是UAF但是其实根本就不算是真正 ...