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".
Sample test(s)
Input
1 5
Output
No
Input
3 6
Output
Yes

题目大意:

    一个工厂,仓库中有X个产品,那么当天就生产X mod M个产品。给一个A代表仓库中的产品个数,问是否存在工厂停工的一天。即X mod M = 0。

解题思路:

    错误思路:

      当时拿到第一组样例进行验算发现:

      第一天 1 5 生产1件

      第二天 2 5 生产2件

      第三天 4 5 生产4件

      第四天 8 5 生产3件

      第五天 11 5 生产1件

      第六天 12 5 生产2件

      可以看到每天的生产数每4天一循环。

      X mod M的结果属于[0,M-1]。那么最多要是在M天以内没有出现 X mod M==0 的情况,就不会在出现了。(根据抽屉原理第M+1次必会重复,但是若出现0就结束判断,只需判断循环M次会不会出现0即可)

Code:

 /*************************************************************************
> File Name: CF485A.cpp
> Author: Enumz
> Mail: 369372123@qq.com
> Created Time: 2014年11月06日 星期四 00时47分17秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<climits>
#define MAXN 100000
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int t=b;
while (t--)
{
if ((a+a%b)%b==)
{
printf("Yes");
return ;
}
else
a=(a+a%b)%b;
}
printf("No");
return ;
}

CodeForces485A——Factory(抽屉原理)的更多相关文章

  1. CodeForces 485A Factory (抽屉原理)

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

  2. uva202:循环小数(循环节+抽屉原理)

    题意: 给出两个数n,m,0<=n,m<=3000,输出n/m的循环小数表示以及循环节长度. 思路: 设立一个r[]数组记录循环小数,u[]记录每次的count,用于标记,小数计算可用 r ...

  3. hdu 3303 Harmony Forever (线段树 + 抽屉原理)

    http://acm.hdu.edu.cn/showproblem.php?pid=3303 Harmony Forever Time Limit: 20000/10000 MS (Java/Othe ...

  4. 《Mathematical Olympiad——组合数学》——抽屉原理

    抽屉原理可以说是组合数学中最简单易懂的一个原理了,其最简单最原始的一个表达形式:对于n本书放到n-1个抽屉中,保证每个抽屉都要有书,则必存在一个抽屉中有2本书.但是这个简单的原理在很多问题中都能够巧妙 ...

  5. poj2356 Find a multiple(抽屉原理|鸽巢原理)

    /* 引用过来的 题意: 给出N个数,问其中是否存在M个数使其满足M个数的和是N的倍数,如果有多组解, 随意输出一组即可.若不存在,输出 0. 题解: 首先必须声明的一点是本题是一定是有解的.原理根据 ...

  6. POJ- Find a multiple -(抽屉原理)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6452   Accepted: 2809   Special Judge D ...

  7. 51nod 1103 N的倍数(抽屉原理)

    1103 N的倍数 题目来源: Ural 1302 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 一个长度为N的数组A,从A中选出若干个数,使得这些数的和是N的倍 ...

  8. CF618F Double Knapsack 构造、抽屉原理

    传送门 首先,选取子集的限制太宽了,子集似乎只能枚举,不是很好做.考虑加强限制条件:将"选取子集"的限制变为"选取子序列"的限制.在接下来的讨论中我们将会知道: ...

  9. poj 2356 (抽屉原理)

    题目链接:http://poj.org/problem?id=2356 题目大意:给你n个数,要你从n个数选出若干个数,要求这若干个数的和是n的倍数,输出选择数的个数,以及相应的数. 解题思路: 以下 ...

随机推荐

  1. LintCode-Serialization and Deserialization Of Binary Tree

    Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a ...

  2. 20145120《Java程序设计》课程总结

    20145120<Java程序设计>课程总结 每周读书笔记链接汇总 寒假学习总结 第1周学习总结 第2周学习总结 第3周学习总结 第4周学习总结 第5周学习总结 第6周学习总结 第7周学习 ...

  3. VIM技巧:翻页

    整页翻页 ctrl-f ctrl-bf=forword b=backward 翻半页ctrl-d ctlr-ud=down u=up 滚一行ctrl-e ctrl-y zz 让光标所在的行居屏幕中央z ...

  4. [Z] 深入浅出 Systemd

    1. Systemd 的简介和特点 Systemd 是 Linux 系统中最新的初始化系统(init),它主要的设计目标是克服 sysvinit 固有的缺点,提高系统的启动速度.systemd 和 u ...

  5. Netsharp快速入门(之11) 销售管理(开发销售订单工作区)

    作者:秋时 杨昶   时间:2014-02-15  转载须说明出处 4.3     销售订单开发 4.3.1  部件工作区设置 1.创建部件工作区,建工作区向导中要注意勾选组合并系部分.具体要建立的部 ...

  6. ubuntu重置root密码

    from: http://mmicky.blog.163.com/blog/static/150290154201398113034698/ 使用ubuntu的时候忘记了root密码该如何重置?我使用 ...

  7. java 命名代码检查-注解处理器

    命名代码检查 根据 <Java 语言规范( 第 3 版 ) > 中第6.8节的要求, Java 程序命名应当符合下列格式的书写规范: 类 ( 或接口 ) : 符合驼式命名法, 首字母大写. ...

  8. Netty 对通讯协议结构设计的启发和总结

    Netty 通讯协议结构设计的总结 key words: 通信,协议,结构设计,netty,解码器,LengthFieldBasedFrameDecoder 原创 包含与机器/设备的通讯协议结构的设计 ...

  9. JS--事件对象中部份浏览器不兼容方法

    测试时主要用的浏览器是Firefox 28.0.IE11.IE8.Chrome 34.0  一.什么是事件对象:当触发某个事件的时候,会产生一个事件对象,这个对象包含着所有的与事件有关的信息,包括导致 ...

  10. Leetcode#59 Spiral Matrix II

    原题地址 相比于Spiral Matrix(参见这篇文章)要简单一些,因为是方阵,所以代码简洁一些. 注意当n是奇数的时候,中心小块要单独赋值(代码21行) 代码: vector<vector& ...