CodeForces485A——Factory(抽屉原理)

时间:2023-05-29 23:19:02

Factory

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".
Sample test(s)
Input
1 5
Output
No
Input
3 6
Output
Yes

题目大意:

    一个工厂,仓库中有X个产品,那么当天就生产X mod M个产品。给一个A代表仓库中的产品个数,问是否存在工厂停工的一天。即X mod M = 0。

解题思路:

    错误思路:

      当时拿到第一组样例进行验算发现:

      第一天 1 5 生产1件

      第二天 2 5 生产2件

      第三天 4 5 生产4件

      第四天 8 5 生产3件

      第五天 11 5 生产1件

      第六天 12 5 生产2件

      可以看到每天的生产数每4天一循环。

      X mod M的结果属于[0,M-1]。那么最多要是在M天以内没有出现 X mod M==0 的情况,就不会在出现了。(根据抽屉原理第M+1次必会重复,但是若出现0就结束判断,只需判断循环M次会不会出现0即可)

Code:

 /*************************************************************************
> File Name: CF485A.cpp
> Author: Enumz
> Mail: 369372123@qq.com
> Created Time: 2014年11月06日 星期四 00时47分17秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<climits>
#define MAXN 100000
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int t=b;
while (t--)
{
if ((a+a%b)%b==)
{
printf("Yes");
return ;
}
else
a=(a+a%b)%b;
}
printf("No");
return ;
}