/**
题目:UVA 12169 Disgruntled Judge
链接:https://vjudge.net/problem/UVA-12169
题意:原题
思路:
a,b范围都在10000以内。暴力枚举1e8;但是还要判断。所以时间不够。 如果可以枚举a,然后算出b,再判断可行性,那么时间上是可行的。但是是多次方的方程无法解。 想其他办法:
xi = (a*xi-1 + b) % 10001 xi+1 = (a*xi+b)%10001 xi+2 = (a*xi+1+b)%10001 => xi+2 = a*(a*xi+b)+b % 10001
= a*a*xi + (a+1)*b % 10001 xi+2 = a*a*xi + (a+1)*b - 10001*k ; 扩展欧几里得求解b。 (a+1)*b - 10001*k = xi+2 - a*a*xi; 因为mod=10001所以,求出任意一个解即可。 哪怕b是负数,+一个mod也是可以变成非负数的。 a*x + b*y = c; c%gcd(a,b)==0; a*1 + b*0 = a; */ #include <iostream>
#include <cstdio> using namespace std;
typedef long long ll;
const int maxn = 1e4+;
ll c[maxn];
int T;
const int mod = 1e4+;
void ext_gcd(ll a,ll b,ll &d,ll &x,ll &y)
{
if(!b) {d = a; x = ; y = ;}
else{
ext_gcd(b,a%b,d,y,x); y = y-x*(a/b);
}
}
bool judge(ll a,ll b)
{
for(int i = ; i < T; i++){
ll t = (a*a*c[i-] + (a+)*b+mod) % mod;
if(t!=c[i]) return false;
}
return true;
}
int main()
{
//freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
while(scanf("%d",&T)==)
{
for(int i = ; i < T; i++){
scanf("%lld",&c[i]);
}
if(T==){
printf("0\n");
continue;
}
ll a, b, d, x, y;
for(int i = ; i < T; i++){
for(a = ; a < mod; a++){
ll temp = c[i]-a*a*c[i-];
ext_gcd(a+,mod,d,x,y);
b = x*(temp/d);
if(b<) b+= mod;
if(judge(a,b)){
break;
}
}
}
for(int i = ; i < T; i++){
printf("%lld\n",(a*c[i]+b+mod)%mod);
}
}
return ;
}

UVA 12169 Disgruntled Judge 扩展欧几里得的更多相关文章

  1. UVA.12169 Disgruntled Judge ( 拓展欧几里得 )

    UVA.12169 Disgruntled Judge ( 拓展欧几里得 ) 题意分析 给出T个数字,x1,x3--x2T-1.并且我们知道这x1,x2,x3,x4--x2T之间满足xi = (a * ...

  2. UVA 12169 Disgruntled Judge 枚举+扩展欧几里得

    题目大意:有3个整数 x[1], a, b 满足递推式x[i]=(a*x[i-1]+b)mod 10001.由这个递推式计算出了长度为2T的数列,现在要求输入x[1],x[3],......x[2T- ...

  3. UVA 10090 Marbles(扩展欧几里得)

    Marbles Input: standard input Output: standard output I have some (say, n) marbles (small glass ball ...

  4. UVa 12169 Disgruntled Judge 紫书

    思路还是按照紫书,枚举a,得出b, 然后验证. 代码参考了LRJ的. #include <cstdio> #include <iostream> using namespace ...

  5. UVA 12169 Disgruntled Judge【扩展欧几里德】

    题意:随机选取x1,a,b,根据公式xi=(a*xi-1+b)%10001得到一个长度为2*n的序列,奇数项作为输入,求偶数项,若有多种,随机输出一组答案. 思路:a和b均未知,可以考虑枚举a和b,时 ...

  6. UVa 12169 - Disgruntled Judge(拓展欧几里德)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. UVA 12169 Disgruntled Judge(Extended_Euclid)

    用扩展欧几里德Extended_Euclid解线性模方程,思路在注释里面了. 注意数据范围不要爆int了. /********************************************* ...

  8. UVA 12169 Disgruntled Judge

    我该怎么说这道题呢...说简单其实也简单,就枚举模拟,开始卡了好久,今天看到这题没a又写了遍,看似会超时的代码交上去a了,果然实践是检验真理的唯一标准... #include <iostream ...

  9. hdu 2769 uva 12169 Disgruntled Judge 拓展欧几里德

    //数据是有多水 连 10^10的枚举都能过 关于拓展欧几里德:大概就是x1=y2,y1=x2-[a/b]y2,按这个规律递归到gcd(a,0)的形式,此时公因数为a,方程也变为a*x+0*y=gcd ...

随机推荐

  1. MySQL Workbench 工具

    http://www.cnblogs.com/mr-wid/archive/2013/05/09/3068229.html http://www.cnblogs.com/daimage/archive ...

  2. transform使用导致元素内字体出现模糊的坑~~~

    项目中遇到的,关于居中弹出层的字体模糊问题. 先来个对比图: 清晰版: 模糊版: 这个是一个不定宽高的弹出框,居中的方式如下代码: .layerdiv { position: fixed; top: ...

  3. TDiocpCoderTcpServer返回数据记录有条数限制的问题

    TDiocpCoderTcpServer返回数据记录有条数限制的问题 在使用TDiocpCoderTcpServer控件返回查询数据的时候,发现当记录条数超过一定数量的时候(比方有人反试图返回30万条 ...

  4. FL2440 rt3070模块station模式动态获取IP地址

    ---------------------------------------------------------------------------------------------------- ...

  5. DevExpress.Build.targets

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <UsingTask ...

  6. [Flutter] Creating, Importing & Using Dynamic Widgets from Other Files in a Flutter Application

    In this lesson we’ll learn how to import widgets we’ve created in other files & use them in our ...

  7. 补番计划 (长沙理工大学第十一届程序设计竞赛)(双端队列+set容器+string)

    补番计划 Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submissi ...

  8. TestNG简单的学习-TestNG运行

    转载:http://topmanopensource.iteye.com/blog/1983735 TestNG简单的学习-TestNG运行 文档来自官方地址: http://testng.org/d ...

  9. 配置git账号和密码

    最开始启动的时候 配置用户名和用户邮箱,安装完git第一件要做的事情! git config --global uesr.name "Sunnshino" git config - ...

  10. Unity AssetBundle 踩坑记录

    Unity AssetBundle 踩坑记录 editor 下选择什么平台的 ab 加载 Material doesn't have a color property '_Color' UnityEd ...