Codeforces Round #276 (Div. 2) Factory

来源:互联网 发布:怎么健身 知乎 编辑:程序博客网 时间:2024/05/01 07:40

题目叙述:

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 werex details in the factory storage, then by the end of the day the factory has to produce (remainder after dividingx 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 bym).

Given the number of details a on the first day and numberm check if the production stops at some moment.

点击打开链接

题目翻译:

开始工厂存储x件产品,但是都买不出去。他们每天生产x mod m件产品,但是也卖不出去(呃~~~)。于是产品就一直在囤积,如果某天x可以整除m,那么工厂就面临大问题了。

算法分析:

设每天其实的产品数位a,第二天起始的产品数为a+a%m,判断a+a%m是否可以被m整除.

判断(a+a%m)是否会重复出现。


我的代码:

#include<iostream>using namespace std;int main(){    int a,m;    int flag=1;    int s[100000]={0};    cin>>a>>m;    while(flag)    {        a=(a+a%m)%m;        if(!a)        {            cout<<"Yes"<<endl;            flag=0;        }        if(s[a]==1)             //判断是否重复出现        {            cout<<"No"<<endl;            flag=0;        }        s[a]=1;                 //数字出现一次    }    return 0;}


0 0