140. Integer Sequences

time limit per test: 0.25 sec. 
memory limit per test: 4096 KB

A sequence A is called an integer sequence of length if all its elements A1 A2 .. AN are non-negative integers less than 2 000 000 000. Consider two integer sequences of length NA and X. The result of their multiplication (A*X) is an integer number R=A1*X1 + A2*X2 + .. + AN*XN. Your task is to solve the equation A*X=B (mod P), given the integer sequence A and the integer numbers B and P.

Input

The first line contains the integer numbers N (1<=N<=100) - the length of the integer sequences - P (1<=P<=10 000) and B (0<=B<=P-1). The second line contains the elements of the sequence A, separated by blanks: A1 A2 .. AN.

Output

You should print one line containing the word "YES" if there exists at least one integer sequence X which is a solution to the equation, or print "NO" otherwise. If the answer is "YES", the next line should contain N non-negative integers separated by blanks: X1 X2 .. XN.

Sample Input #1

2 7 4
7 3

Sample Output #1

YES
0 6

Sample Input #2

3 10 1
2 4 6

Sample Output #2

NO
线性同余方程,不断使前k个项余p得到最大公约数,同除去最大公约数,逆推即可
#include <cstdio>
using namespace std;
int extgcd(int a,int b,int& x,int& y){
if(a==0){
x=0;y=1;
return b;
}
int t=extgcd(b%a,a,x,y);
int temp=x;
x=y-b/a*x;
y=temp;
return t;
}
int num[110],x[110],y[110];
int main(){
int cgcd,n,p,b;
scanf("%d%d%d",&n,&p,&b);
for(int i=0;i<n;i++){
scanf("%d",num+i);
num[i]%=p;
}
cgcd=num[0];
for(int i=1;i<n;i++){
cgcd=extgcd(cgcd,num[i],x[i],y[i]);
}
cgcd=extgcd(cgcd,p,x[n],y[n]);
if(b%cgcd!=0)puts("NO");
else {
puts("YES");
b/=cgcd;
y[0]=1;
for(int i=n-1;i>=0;i--){
while(x[i+1]<0)x[i+1]+=p;
b*=x[i+1];
b%=p;
while(y[i]<0)y[i]+=p;
y[i]=y[i]*b%p;
}
for(int i=0;i<n;i++){
printf("%d%c",y[i],i==n-1?'\n':' ');
}
}
return 0;
}

  

SGU 140. Integer Sequences 线性同余,数论 难度:2的更多相关文章

  1. sgu 137. Funny Strings 线性同余,数论,构造 难度:3

    137. Funny Strings time limit per test: 0.25 sec. memory limit per test: 4096 KB Let's consider a st ...

  2. POJ 3087 Shuffle'm Up 线性同余,暴力 难度:2

    http://poj.org/problem?id=3087 设:s1={A1,A2,A3,...Ac} s2={Ac+1,Ac+2,Ac+3,....A2c} 则 合在一起成为 Ac+1,A1,Ac ...

  3. POJ 1426 Find the Multiple 思路,线性同余,搜索 难度:2

    http://poj.org/problem?id=1426 测试了一番,从1-200的所有值都有long long下的解,所以可以直接用long long 存储 从1出发,每次向10*s和10*s+ ...

  4. 解密随机数生成器(二)——从java源码看线性同余算法

    Random Java中的Random类生成的是伪随机数,使用的是48-bit的种子,然后调用一个linear congruential formula线性同余方程(Donald Knuth的编程艺术 ...

  5. python3 线性同余发生器 ( random 随机数生成器 ) 伪随机数产生周期的一些探究

    import random x=[str(random.randint(0, 5)) for i in range(10)] x_str=''.join(x) y=[str(random.randin ...

  6. K - Large Division 判断a是否是b的倍数。 a (-10^200 ≤ a ≤ 10^200) and b (|b| > 0, b fits into a 32 bit signed integer). 思路:取余;

    /** 题目:K - Large Division 链接:https://vjudge.net/contest/154246#problem/K 题意:判断a是否是b的倍数. a (-10^200 ≤ ...

  7. Finite Encyclopedia of Integer Sequences(找规律)

    6617: Finite Encyclopedia of Integer Sequences 时间限制: 1 Sec  内存限制: 128 MB提交: 375  解决: 91[提交] [状态] [讨论 ...

  8. ACM程序设计选修课——1043: Radical loves integer sequences(YY)

    1043: Radical loves integer sequences Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 36  Solved: 4 ...

  9. hdu1573:数论,线性同余方程组

    题目大意: 给定一个N ,m 找到小于N的  对于i=1....m,满足  x mod ai=bi  的 x 的数量. 分析 先求出 同余方程组 的最小解x0,然后 每增加lcm(a1...,am)都 ...

随机推荐

  1. IntelliJ IDEA 、PyCharm、WebStorm、PhpStorm等JetBrains公司软件 激活的License Server本地搭建教程

    一.背景 IntelliJ IDEA是JetBrains公司的一款IDE,主要用于java开发,可以编写Java.Groovy.Kotlin.Scala等语言,也可以直接做Android开发. 同系列 ...

  2. day18(JDBC事务&连接池介绍&DBUtils工具介绍&BaseServlet作用)

    day18总结 今日思维导图: 今日内容 事务 连接池 ThreadLocal BaseServlet自定义Servlet父类(只要求会用,不要求会写) DBUtils à commons-dbuti ...

  3. 001-Spring的设计理念和整体架构

    一.概述 1.1.Spring的各个子项目 网站:https://spring.io/ 基于Spring的项目:https://spring.io/projects 文档列表:https://spri ...

  4. js-template-art【一】简述

    一.官方地址 地址:https://github.com/aui/art-template 二.概述 官方对比 三.特性 拥有接近 JavaScript 渲染极限的的性能 调试友好:语法.运行时错误日 ...

  5. ZOJ Monthly, January 2019

    A: Little Sub and Pascal's Triangle Solved. 题意: 求杨辉三角第n行奇数个数 思路: 薛聚聚说找规律,16说Lucas 答案是 $2^p \;\;p 为 n ...

  6. python webdriver api-操作富文本框

    操作富文本框-就是邮件正文部分,可以选字体啥的 第一种方式: 一般都是在iframe里,要切进去,一般是”html/body”,编辑之后,再切出来,然后再send_keys就完事儿 #encoding ...

  7. 20145312《网络对抗》Exp4 恶意代码分析

    20145312<网络对抗>Exp4 恶意代码分析 问题回答 1.总结一下监控一个系统通常需要监控什么.用什么来监控. 监控一个系统通常需要监控这个系统的注册表,进程,开放端口,程序服务还 ...

  8. MS08_067漏洞渗透攻击

    MS08_067漏洞渗透攻击实践 前期准备 kali和winxp要ping通 kali开启msfconsole: 同时在这里可以看到目前可攻击载荷个数一共是471个,也可以看到其他攻击的数量如图. 用 ...

  9. 想转行学Java,却又担心自己半路出家成不了大牛

    想转行学Java,却又担心自己半路出家成不了大牛 很多人看好Java编程的高薪前景,在自己职业生涯迷茫的时候,想转行学Java,却又担心自己半路出家成不了大牛,赚不到钱,本文就为大家分析一下,转行学J ...

  10. [参考]用递归的方法获取 字符 对应的 二进制字符串 (C/C++)

    将字符转换为16进制字符串.十进制字符串可以参考这里:https://www.cnblogs.com/stxs/p/8846545.html 代码及调试结果 举例:字符'a',查ASCII码表它对应的 ...