我作为一个初中蒟蒻,听y大视频听了5遍还不懂,快哭了.然后终于(好像)搞懂,写成题解加深一下记忆... 将式子等价转换 对于每两个式子(我们考虑将其合并): \(x \equiv a_1 \%\ m_1\) \(x \equiv a_2 \%\ m_2\) 则有: \(x = k_1 * a_1 + m_1\) \(x = k_2 * a_2 + m_2\) 进一步: \(k_1 * a_1 + m_1 = k_2 * a_2 + m_2\) 移项: \(k_1 * a_1 - k_2 * a_…
给定2n个整数a1,a2,…,ana1,a2,…,an和m1,m2,…,mnm1,m2,…,mn,求一个最小的整数x,满足∀i∈[1,n],x≡mi(mod ai)∀i∈[1,n],x≡mi(mod ai). 输入格式 第1行包含整数n. 第2..n行:每i+1行包含两个整数aiai和mimi,数之间用空格隔开. 输出格式 输出整数x,如果x不存在,则输出-1. 数据范围 1≤ai≤231−11≤ai≤231−1,0≤mi<ai0≤mi<ai 输入样例: 2 8 7 11 9 输出样例:31…
#include<bits/stdc++.h> using namespace std; typedef long long LL; LL exgcd(LL a,LL b,LL &x,LL &y) { if(!b) { x=1,y=0; return a; } LL d=exgcd(b,a%b,y,x); y-=a/b*x; return d; } int main() { int n; LL a1,m1; cin>>n>>a1>>m1; L…
Strange Way to Express Integers DescriptionElina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is described as following:Choose k different positive integers a1, a2, …, ak. For some n…
I. Strange Way to Express Integers 题目描述 原题来自:POJ 2891 给定 2n2n2n 个正整数 a1,a2,⋯,ana_1,a_2,\cdots ,a_na​1​​,a​2​​,⋯,a​n​​ 和 m1,m2,⋯,mnm_1,m_2,\cdots ,m_nm​1​​,m​2​​,⋯,m​n​​,求一个最小的正整数 xxx,满足 ∀i∈[1,n],x≡ai (modmi ),或者给出无解. 输入格式 多组数据. 每组数据第一行一个整数 nnn:接下来 nn…
Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 9472   Accepted: 2873 Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is…
Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 10907   Accepted: 3336 Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is…
F - Strange Way to Express Integers Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u Submit Status Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers.…
Strange Way to Express Integers Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2891   Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative i…
1635:[例 5]Strange Way to Express Integers sol:貌似就是曹冲养猪的加强版,初看感觉非常没有思路,经过一番艰辛的***,得到以下的结果 随便解释下给以后的自己听:K是要求的数字 第一个读入的A1,Mod1不用改,从2开始做,把Mod2改成LCM,A2改成Ans,接着搞3 /* 原式: X = A[1] (%Mod[1]) X = A[2] (%Mod[2]) ... X = A[n] (%Mod[n]) K[1]*Mod[1]+A[1] = X K[2]…