Description
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 Input
1 5
No
3 6
Yes
题目解析:给出工厂初始的产品,给出m,用前一天的产品对m取余,看是否能等于0;如果可以输出yes,否则输出no;
题目链接:http://codeforces.com/problemset/problem/485/A
源代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int ans=0;
int main()
{
int a,m;
scanf("%d%d",&a,&m);
int d=0;
while(1)
{
if(a%m==0)
{
d=1;
break;
}
a=(a+a)%m;
ans++;
if(ans>m)
{
break;
}
}
if(d)
printf("Yes\n");
else
printf("No\n");
return 0;
}
。。其实是水题,可是我tm被卡了1个多小时。。