UVA - 12169 -扩展欧几里得算法
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#define ll long long
#define rep(i,j,k) for(int i=j;i<=k;++i)
using namespace std;
const int maxx = 1e4+;
ll a[maxx];
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y)
{
if (!b)
{
d=a;
x=;
y=;
}
else
{
ex_gcd(b,a%b,d,y,x);
y-=x*(a/b);
}
}
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(a,,sizeof(a));
for (int i=; i<=*n; i+=)
{
scanf("%lld",&a[i]);
}
ll d,k,b;
rep(i,,)
{
ex_gcd(,i+,d,k,b);
ll c=(a[]-(ll)i*i*a[]);//等式左边
b=b*c/d;//解数字解
if(c%d==)
{
int flag;
rep(j,,*n)
{
flag=;
ll tmp=(i*a[j-]+b)%;
if (j%==)
{
if (tmp!=a[j])
{
flag=;
break;
}
}else {
a[j]=tmp;
}
}
if (flag)
{
break;
}
}
else
{
continue;
}
}
for (int i=;i<=*n;i+=){
printf("%lld\n",a[i]);
} }
return ;
}
UVA - 12169 -扩展欧几里得算法的更多相关文章
- 扩展欧几里得算法(extgcd)
相信大家对欧几里得算法,即辗转相除法不陌生吧. 代码如下: int gcd(int a, int b){ return !b ? gcd(b, a % b) : a; } 而扩展欧几里得算法,顾名思义 ...
- noip知识点总结之--欧几里得算法和扩展欧几里得算法
一.欧几里得算法 名字非常高大上的不一定难,比如欧几里得算法...其实就是求两个正整数a, b的最大公约数(即gcd),亦称辗转相除法 需要先知道一个定理: gcd(a, b) = gcd(b, a ...
- 欧几里得算法与扩展欧几里得算法_C++
先感谢参考文献:http://www.cnblogs.com/frog112111/archive/2012/08/19/2646012.html 注:以下讨论的数均为整数 一.欧几里得算法(重点是证 ...
- vijos1009:扩展欧几里得算法
1009:数论 扩展欧几里得算法 其实自己对扩展欧几里得算法一直很不熟悉...应该是因为之前不太理解的缘故吧这次再次思考,回看了某位大神的推导以及某位大神的模板应该算是有所领悟了 首先根据题意:L1= ...
- ****ural 1141. RSA Attack(RSA加密,扩展欧几里得算法)
1141. RSA Attack Time limit: 1.0 secondMemory limit: 64 MB The RSA problem is the following: given a ...
- 浅谈扩展欧几里得算法(exgcd)
在讲解扩展欧几里得之前我们先回顾下辗转相除法: \(gcd(a,b)=gcd(b,a\%b)\)当a%b==0的时候b即为所求最大公约数 好了切入正题: 简单地来说exgcd函数求解的是\(ax+by ...
- (light oj 1306) Solutions to an Equation 扩展欧几里得算法
题目链接:http://lightoj.com/volume_showproblem.php?problem=1306 You have to find the number of solutions ...
- 『扩展欧几里得算法 Extended Euclid』
Euclid算法(gcd) 在学习扩展欧几里得算法之前,当然要复习一下欧几里得算法啦. 众所周知,欧几里得算法又称gcd算法,辗转相除法,可以在\(O(log_2b)\)时间内求解\((a,b)\)( ...
- 题解——洛谷P2613 【模板】有理数取余(扩展欧几里得算法+逆元)
题面 题目描述 给出一个有理数 c=\frac{a}{b} ,求 c mod19260817 的值. 输入输出格式 输入格式: 一共两行. 第一行,一个整数 \( a \) .第二行,一个整 ...
随机推荐
- 文件服务器HFS
用途:用于文件共享(类似FTP) 官网:http://www.rejetto.com/hfs/?f=ss 优点:比起apache,它有界面方便查看当前正连接的主机 如果在内网环境下进行文件共享的话,可 ...
- php伪协议,利用文件包含漏洞
php支持多种封装协议,这些协议常被CTF出题中与文件包含漏洞结合,这里做个小总结.实验用的是DVWA平台,low级别,phpstudy中的设置为5.4.45版本, 设置allow_url_fopen ...
- kafka_2.11-2.0.0_安装部署
参考博文:kafka 配置文件参数详解 参考博文:Kafka[第一篇]Kafka集群搭建 参考博文:如何为Kafka集群选择合适的Partitions数量 参考博文:Kafka Server.prop ...
- Eric Chen Mock Interview
Given an array with integers. Find two non-overlapping subarrays A and B, which |SUM(A) - SUM(B)| is ...
- 谱聚类算法(Spectral Clustering)优化与扩展
谱聚类(Spectral Clustering, SC)在前面的博文中已经详述,是一种基于图论的聚类方法,简单形象且理论基础充分,在社交网络中广泛应用.本文将讲述进一步扩展其应用场景:首先是User- ...
- Error response from daemon:###unable to delete ### (must be forced) - image is being used by stopped
具体错误:Error response from daemon: conflict: unable to delete f2e2f7b8308b (must be forced) - image is ...
- node.js—File System(文件系统模块)
文件系统模块概述 该模块是核心模块,提供了操作文件的一些API,需要使用require导入后使用,通过 require('fs') 使用该模块 文件 I/O 是由简单封装的标准 POSIX 函数提供的 ...
- 7.01-beautiful_soup3
# pip install beautifulsoup4 from bs4 import BeautifulSoup html_doc = """ <html> ...
- raise ValueError("Cannot convert {0!r} to Excel".format(value))
I have hundreds of XML files that I need to extract two values from and ouput in an Excel or CSV fil ...
- sqlserver 2000数据压缩解决方法
--sqlserver 2000数据压缩解决方法. /************************************************************************* ...