Codeforces 485 A. Factory 暴力


乱暴力就可以了....

A. Factory
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 xby 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

/**
 * Created by ckboss on 14-11-7.
 */
import java.util.*;

public class CF485A
{
    public static void main(String[] args)
    {
        HashSet<Integer> hi = new HashSet<Integer>();
        Scanner in = new Scanner(System.in);
        int a,m;
        a=in.nextInt(); m=in.nextInt();
        boolean flag=false;
        for(int i=0;i<=100000;i++)
        {
            a=(a+a%m)%m;
            if(hi.contains(a)==true)
                break;
            hi.add(a);
            if(a%m==0)
            {
                flag=true; break;
            }
        }
        if(flag==true)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值