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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 485A】Factory (水题,抽屉原理,tricks)

發(fā)布時(shí)間:2023/12/10 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 485A】Factory (水题,抽屉原理,tricks) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題干:

One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were?x?details in the factory storage, then by the end of the day the factory has to produce??(remainder after dividing?x?by?m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.

The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by?m).

Given the number of details?a?on the first day and number?m?check if the production stops at some moment.

Input

The first line contains two integers?a?and?m?(1?≤?a,?m?≤?105).

Output

Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".

Examples

Input

1 5

Output

No

Input

3 6

Output

Yes

題目大意:

?給兩個(gè)數(shù)a和m,每天進(jìn)行一次操作,a = (a+a%m)%m, 問a是否有可能等于0思路:

解題報(bào)告:

本來想直接看gcd、、、但是仔細(xì)讀題發(fā)現(xiàn)不行,因?yàn)樗@個(gè)沒大有規(guī)律啊、、、所以沒有類似的結(jié)論可以用,

因?yàn)閍和m小于10^5,而且a每次都要取余,所以a每天操作之后的變成的值肯定小于m,即小于10^5,開個(gè)vis數(shù)組,記錄下a曾經(jīng)取過什么數(shù),每次操作后判斷如果a出現(xiàn)過,那就是進(jìn)入循環(huán)了輸出No,如果a==0就符合要求輸出Yes。

根據(jù)抽屜原理,最多進(jìn)行m+1天一定會(huì)有重復(fù)出現(xiàn)的余數(shù),時(shí)間復(fù)雜度O(m)。

當(dāng)然這題還有個(gè)O(logm) 的做法:

我們推算兩步:(a + (a mod m)) mod m = ((a mod m) + (a mod m)) mod m = (2*a) mod m。也就是說接下來的所有答案都是2的冪次,也就是說?如果存在K?≥?0 ,使得,那么輸出Yes,否則輸出No。題目范圍1e5,也就是說我們只需要推算大概20步,就可以break了。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair using namespace std; const int MAX = 2e5 + 5; int n,x,y,a[MAX],ans; const ll INF = 0x3f3f3f3f3f; int main() {ll a,m;int flag = 0;scanf("%lld%lld",&a,&m);for(int i = 1; i<=100000; i++) {if(a%m == 0) flag = 1;a = (a+a)%m;}if(flag) puts("Yes");else puts("No");return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的【CodeForces - 485A】Factory (水题,抽屉原理,tricks)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。