日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

hdu3579(中国剩余问题经典)

發布時間:2024/8/23 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu3579(中国剩余问题经典) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Description

One day I was shopping in the supermarket. There was a cashier(收銀員)?counting coins seriously when a little kid running and singing "門前大橋下游過一群鴨,快來快來 數一數,二四六七八". And then the cashier put the counted coins back morosely(愁眉苦臉的)?and count again...?
Hello Kiki is such a lovely girl that she loves doing counting in a different way. For example, when she is counting X coins, she count them N times. Each time she divide the coins into several same sized groups and write down the group size Mi and the number of the remaining coins Ai on her note.?
One day Kiki's father found her note and he wanted to know how much coins Kiki was counting.

Input

The first line is T indicating the number of test cases.?
Each case contains N on the first line, Mi(1 <= i <= N) on the second line, and corresponding(相當的)?Ai(1 <= i <= N) on the third line.?
All numbers in the input and output are integers.?
1 <= T <= 100, 1 <= N <= 6, 1 <= Mi <= 50, 0 <= Ai < Mi

Output

For each case output the least positive integer X which Kiki was counting in the sample output format. If there is no solution then output -1.?

Sample Input

2

2

14 57

5 56

5

19 54 40 24 80

11 2 36 20 76

Sample Output

Case 1: 341

Case 2: 5996

題意:res%14=5 res%57=56 res

思路:套用中國剩余問題的模板

代碼:

#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<math.h> #include<set> #include<queue> #include<vector> using namespace std; #define N 10005 #define ll __int64 ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a%b); } //求一組解(x,y)使得 ax+by = gcd(a,b), 且|x|+|y|最小(注意求出的 x,y 可能為0或負數)。 //下面代碼中d = gcd(a,b) //可以擴展成求等式 ax+by = c,但c必須是d的倍數才有解,即 (c%gcd(a,b))==0 void extend_gcd (ll a , ll b , ll& d, ll &x , ll &y) { if(!b){d = a; x = 1; y = 0;}else {extend_gcd(b, a%b, d, y, x); y-=x*(a/b);} } ll inv(ll a, ll n) { //計算%n下 a的逆。如果不存在逆return -1;ll d, x, y;extend_gcd(a, n, d, x, y);return d == 1 ? (x+n)%n : -1; } ll n[N],b[N],len,lcm; ll work(){for(ll i = 2; i <= len; i++) {ll A = n[1], B = n[i], d, k1, k2, c = b[i]-b[1];extend_gcd(A,B,d,k1,k2);if(c%d)return -1;ll mod = n[i]/d;ll K = ((k1*(b[i]-b[1])/d)%mod+mod)%mod;b[1] = n[1]*K + b[1];n[1] = n[1]*n[i]/d;}if(b[1]==0)return lcm;return b[1]; } int main(){ll i,T,Cas=1;cin>>T;while(T--){cin>>len;lcm = 1;for(i=1;i<=len;i++) {cin>>n[i];lcm = lcm / gcd(lcm,n[i]) * n[i];}for(i=1;i<=len;i++)cin>>b[i];cout<<"Case "<<Cas++<<": ";cout<<work()<<endl;}return 0; }


總結

以上是生活随笔為你收集整理的hdu3579(中国剩余问题经典)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产成人精品无码免费看在线 | 日本一区二区黄色 | av毛片在线 | 麻豆精品一区二区 | www亚洲成人 | 特大黑人娇小亚洲女mp4 | 黑人巨大精品欧美一区二区免费 | 狠狠搞狠狠干 | 亚洲作爱网 | 国产成人精品aa毛片 | 精品一区二区三区成人免费视频 | 啊灬啊灬啊灬秀婷 | 在线观看毛片视频 | 精品人妻少妇一区二区三区 | 永久视频在线观看 | 亚洲日本中文字幕在线 | 亚洲天堂一区二区三区四区 | 亚洲成色www久久网站 | 男人你懂的网站 | 欧美在线视频一区二区 | 蜜臀人妻四季av一区二区不卡 | 国产又粗又硬视频 | 国产九九精品 | 日韩成人专区 | 日本福利视频导航 | 一区二区中文 | 久久精品国产熟女亚洲AV麻豆 | 欧美在线国产 | 久久久噜噜噜久久 | 一本一道无码中文字幕精品热 | 成人综合激情 | 中文字幕日韩久久 | 四虎国产精品永久在线国在线 | 久久7777| 神马午夜在线 | 又粗又大又硬毛片免费看 | 欧美精品久久久久久久免费 | 国产一级久久久 | jizzz18| 国产精品拍拍 | 欧美日韩国产激情 | 日本va欧美va欧美va精品 | 日本精品视频在线 | 日本三级视频在线 | 免费色片| 中文字幕免费在线观看 | 亚洲精品国产综合 | 久久久久久国产精品无码 | 国产精品999在线观看 | 国产精久久一区二区三区 | 尤物网址在线观看 | 天堂av网在线 | 亚洲最大色网站 | 中文字幕高清在线观看 | 自拍偷拍亚洲一区 | 亚洲熟女乱综合一区二区 | 丹丹的呻吟声1一7 | 精品区在线观看 | 91看片网站| 最近中文字幕在线中文视频 | 国产精品99久久久久久人 | 成人免费区一区二区三区 | 欧美在线激情 | 中文字幕第一页亚洲 | 天堂在线成人 | 漂亮人妻被中出中文字幕 | 少妇诱惑av | 蜜桃臀aⅴ精品一区二区三区 | 日本免费精品视频 | 中文无码精品一区二区三区 | 精品久久久中文字幕 | 日韩三级视频在线 | 国产精品海角社区 | 超碰在线视屏 | 欧美日韩中文字幕在线观看 | 日韩精品高清在线观看 | 久久中文字幕视频 | 欧美久久99 | 老女人一毛片 | 色就是色欧美 | 在线视频啪| 欧美一级在线免费 | 国产夜色精品一区二区av | www.色哟哟 | 色婷婷av一区二区三 | 青青草超碰在线 | 欧美又大又硬又粗bbbbb | 成人深夜福利在线观看 | 免费草逼视频 | 国产电影一区在线观看 | 农村黄色片 | 一区二区免费在线视频 | 麻豆精品久久久 | 91一区二区三区在线 | 天天宗合网 | 亚洲国产日韩在线 | 久久免费视频观看 | 免费在线观看网址入口 | 浓精喷进老师黑色丝袜在线观看 |