zoukankan      html  css  js  c++  java
  • 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".

    Examples

    Input
    1 5
    Output
    No
    Input
    3 6
    Output
    Yes

    此题就是给你a,m。每天进行a = a+(a%m)操作。让你判断,如果最终a不能被m整除,输出No,否则输出yes。
    代码如下
    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    bool vis[100010];
    int a,m;
    int main()
    {
        cin>>a>>m;
        memset(vis,0,sizeof(vis));
        if(a%m==0)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        while(1)
        {
            a=(a+a%m)%m;
            if(a==0)
            {
                cout<<"Yes"<<endl;
                 return 0;
            }
            if(vis[a])
            {
                cout<<"No"<<endl;
                return 0;
            }
            vis[a]=1;
        }
        return 0;   
    }
  • 相关阅读:
    LiveNVS实现摄像头RTSP无插件播放,并集中化管理
    liveplayer免费网页直播_点播播放器-页面动态多播放器添加代码示例
    JavaScript之图片滚动
    JavaScript之图片轮换
    DOS命令
    jquery之音乐均衡器
    JavaScript之可运行按钮
    jQuery之点击弹出图标环形菜单
    Android之View方法
    Android之所有权限
  • 原文地址:https://www.cnblogs.com/ylrwj/p/10913998.html
Copyright © 2011-2022 走看看