![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
线性同余方程
tomjobs
别慌,慌也没用
展开
-
Codeforces1389 E. Calendar Ambiguity(同余方程化简,等差数列)
Berland year consists of ???? months with ???? days each. Months are numbered from 1 to ????. Berland week consists of ???? days. The first day of the year is also the first day of the week. Note that the last week of the year might be shorter than ???? da原创 2020-07-30 21:32:56 · 423 阅读 · 0 评论 -
ACWING204. 表达整数的奇怪方式(线性同余方程)
给定2n个整数a1,a2,…,an和m1,m2,…,mn,求一个最小的非负整 数x,满足∀i∈[1,n],x≡mi(mod ai)。 输入格式 第1行包含整数n。 第2…n行:每i+1行包含两个整数ai和mi,数之间用空格隔开。 输出格式 输出最小非负整数x,如果x不存在,则输出-1。 如果存在x,则数据保证x一定在64位整数范围内。 数据范围 1≤ai≤231−1, 0≤mi<ai 1≤n...原创 2020-03-12 20:37:41 · 207 阅读 · 1 评论 -
ACWING203. 同余方程(线性同余方程)
求关于x的同余方程 ax ≡ 1(mod b) 的最小正整数解。 输入格式 输入只有一行,包含两个正整数a,b,用一个空格隔开。 输出格式 输出只有一行,包含一个正整数x,表示最小正整数解。 输入数据保证一定有解。 数据范围 2≤a,b≤2∗109 输入样例: 3 10 输出样例: 7 思路: ax≡1(modb)ax \equiv 1(mod b)ax≡1(modb)可以变形为 a∗x−b∗y=...原创 2020-03-12 17:18:38 · 213 阅读 · 1 评论 -
BZOJ4724. [POI2017]Podzielno (神题,数论+二分)
Description B进制数,每个数字i(i=0,1,…,B-1)有a[i]个。你要用这些数字组成一个最大的B进制数X(不能有前导零,不需要 用完所有数字),使得X是B-1的倍数。q次询问,每次询问X在B进制下的第k位数字是什么(最低位是第0位)。 Input 第一行包含两个正整数B(2<=B<=106),q(1<=q<=105)。 第二行包含B个正整数a[0],a[1...原创 2019-11-30 18:46:07 · 287 阅读 · 0 评论