SGU140. Integer Sequences
https://codeforces.com/problemsets/acmsguru/problem/99999/140
n元同余方程的求解
对于任意二元我们可以替换成kgcd(a,b),不断迭代下去最后会变成ax=b(mod p)的情况,然后,再返回去求解,得到g,然后后面变成不等式求解,直接将y[i-1]*g即可,但是要最小整数解。过程当中不断的用p取模,这样可以保证结果不会很大。因为只要一个结果,通项公式为b/d的一个组合,小的约束小,大的约束大, 大的一定包含在小的里面,那么大的一定是其中的一个解,所以mod p,但这并不是最小解,而是一个整数解。
1 #include<bits/stdc++.h>
2 using namespace std;
3 typedef long long ll;
4 ll ex_gcd(ll a,ll b,ll &x,ll &y)
5 {
6 if(!b){x=1,y=0;return a;}
7 ll d=ex_gcd(b,a%b,x,y);
8 ll tmp=x;
9 x=y;y=tmp-a/b*y;
10 return d;
11 }
12 const ll N=520;
13 ll n,m[N],p,b,x[N],y[N],ans[N];
14 int main()
15 {
16 scanf("%lld%lld%lld",&n,&p,&b);
17 for(int i=1;i<=n;i++) scanf("%lld",&m[i]),m[i]%=p;
18 ll g=m[1];m[n+1]=p;
19 for(int i=1;i<=n;i++) g=ex_gcd(g,m[i+1],x[i],y[i]);
20 if(b%g) printf("NO\n");
21 else
22 {
23 printf("YES\n");
24 g=b/g,y[0]=1;
25 for(int i=n;i>=1;i--)
26 {
27 g=(g*x[i]%p+p)%p;
28 ans[i]=(g*y[i-1]%p+p)%p;
29 }
30 for(int i=1;i<=n;i++) printf("%lld%c",ans[i],(i==n?'\n':' '));
31 }
32 return 0;
33 }
SGU140. Integer Sequences的更多相关文章
- SGU 140. Integer Sequences 线性同余,数论 难度:2
140. Integer Sequences time limit per test: 0.25 sec. memory limit per test: 4096 KB A sequence A is ...
- Finite Encyclopedia of Integer Sequences(找规律)
6617: Finite Encyclopedia of Integer Sequences 时间限制: 1 Sec 内存限制: 128 MB提交: 375 解决: 91[提交] [状态] [讨论 ...
- ACM程序设计选修课——1043: Radical loves integer sequences(YY)
1043: Radical loves integer sequences Time Limit: 1 Sec Memory Limit: 128 MB Submit: 36 Solved: 4 ...
- Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)
Problem Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description T ...
- [Swift]LeetCode801. 使序列递增的最小交换次数 | Minimum Swaps To Make Sequences Increasing
We have two integer sequences A and B of the same non-zero length. We are allowed to swap elements A ...
- [LeetCode] Minimum Swaps To Make Sequences Increasing 使得序列递增的最小交换
We have two integer sequences A and B of the same non-zero length. We are allowed to swap elements A ...
- 801. Minimum Swaps To Make Sequences Increasing
We have two integer sequences A and B of the same non-zero length. We are allowed to swap elements A ...
- 801. Minimum Swaps To Make Sequences Increasing 为使两个数组严格递增,所需要的最小交换次数
[抄题]: We have two integer sequences A and B of the same non-zero length. We are allowed to swap elem ...
- LeetCode 801. Minimum Swaps To Make Sequences Increasing
原题链接在这里:https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing/ 题目: We have two in ...
随机推荐
- 分布式可扩展web体系结构设计实例分析
Web分布式系统设计准则 下面以一个上传和查询图片的例子来说明分布式web结构的设计考虑和常用的提高性能的方法.该例子提供上传图片和下载图片两个简单功能,并且有一下假设条件?: - 可以存储无上限数量 ...
- [BUUCTF]PWN——0ctf_2017_babyheap
0ctf_2017_babyheap 附件 步骤: 例行检查,64位程序,保护全开 本地试运行一下,看看大概的情况,经典的堆题的菜单 main函数 add() edit() delete() show ...
- [BUUCTF]REVERSE——[WUSTCTF2020]level3
[WUSTCTF2020]level3 附件 步骤: 例行检查,64位程序,无壳 64位ida载入,找到关键函数 看样子是个base64加密,但又感觉没那么简单,再翻翻左边的函数,找到了base64加 ...
- Niushop开源商店渗透测试
靶机 提取码:le8l 首先连上靶机 先扫一下靶场ip,看看开启了哪些端口 开启了80端口,扫描一下目录 一个shop的界面, 一个admin后台管理界面 其他的目录翻看了一下, 看样子是网站的配置文 ...
- 扬我国威,来自清华的开源项目火爆Github
前几天TJ君跟大家分享了几个有趣的Github项目(加密解密.食谱.新冠序列,各种有趣的开源项目Github上都有),其中呢,有不少是来自斯坦福大学的项目,当时TJ君就不由得想,什么时候能看到的项目都 ...
- python 学生信息管理系统
python与数据库的例子 初始化数据库 链接数据库创建库和表并插入数据 init.py import pymysql sql_base='create database school;' sql_t ...
- SQL注入绕过
空格字符绕过 %09 TAB建(水平) %0a 新建一行,换行 %0b TAB建(垂直) %0c 新的一页 %0d return 功能 %a0 空格 %00 /**/ /*!*/./*!50009*/ ...
- JAVA实现查询栏目、类别(菜单)返回树结构(递归)
其中Channel.java是栏目结构,ChannelDto是我自己封装的返回给前端的数据,可以根据自己的来 这个的逻辑就是双重循环遍历每个类别,然后判断如果当前类别是其他类别的父级,那么就把其他类别 ...
- JAVA获取当前日期指定月份后(多少个月后)的日期
环境要求:使用jdk1.8 package com.date; import java.text.ParseException; import java.text.SimpleDateFormat; ...
- 【LeetCode】270. Closest Binary Search Tree Value 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetco ...