乱暴力就可以了….

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");
    }
}


版权声明:本文为u012797220原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/u012797220/article/details/40894113