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

题意: 给两个数a和m,每天进行一次操作,a = (a+a%m)%m, 问a是否有可能等于0

思路: 因为a和m小于10^5,而且a每次都要取余,所以a每天操作之后的变成的值肯定小于m,即小于10^5,开个vis数组,记录下a曾经取过什么数,每次操作后判断如果a出现过,那就是进入循环了输出No,如果a==0就符合要求输出Yes。
根据抽屉原理,最多进行m+1天一定会有重复出现的余数,时间复杂度O(m)。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1e9;
const double eps = 1e-;
const int N = ;
int cas = ; bool vis[N];
int a,m; void run()
{
memset(vis,,sizeof(vis));
if(a%m==){
puts("Yes");
return;
}
while(true)
{
a = (a+a%m)%m;
if(a==){
puts("Yes");
return;
}
if(vis[a]){
puts("No");
return;
}
vis[a]=;
}
} int main()
{
#ifdef LOCAL
// freopen("case.txt","r",stdin);
#endif
while(cin>>a>>m)
run();
return ;
}

CodeForces 485A Factory (抽屉原理)的更多相关文章

  1. CodeForces485A——Factory(抽屉原理)

    Factory One industrial factory is reforming working plan. The director suggested to set a mythical d ...

  2. codeforces 485A.Factory 解题报告

    题目链接:http://codeforces.com/problemset/problem/485/A 题目意思:给出 a 和 m,a 表示第一日的details,要求该日结束时要多生产 a mod ...

  3. [codeforces 618 F] Double Knapsack (抽屉原理)

    题目链接:http://codeforces.com/contest/618/problem/F 题目: 题目大意: 有两个大小为 N 的可重集 A, B, 每个元素都在 1 到 N 之间. 分别找出 ...

  4. Codeforces Round #319 (Div. 2) B. Modulo Sum 抽屉原理+01背包

    B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  5. Codeforces 958C3 - Encryption (hard) 区间dp+抽屉原理

    转自:http://www.cnblogs.com/widsom/p/8863005.html 题目大意: 比起Encryption 中级版,把n的范围扩大到 500000,k,p范围都在100以内, ...

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

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

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

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

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

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

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

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

随机推荐

  1. python 基础 1.5 python 数据类型(一)--整型 浮点型 布尔型及字符串和常用方法

    一.python 数据类型:数值,字符串,列表,元组,字典.以下操作是在linux 下 ipython中进行 1.数值 1>123  与  “123”的区别 答:123为数值,“123”在pyt ...

  2. Java 学习 day05

    01-面向对象(概述) 面向对象 -- 冰箱.打开:冰箱.存储:冰箱.关闭: 02-面向对象(举例) 使用和指挥 -- 对象,不需要关注过程,只关注结果: 一切皆对象,万物皆对象  -- 自<T ...

  3. android菜鸟学习笔记8----Activity(一)

    Activity是android应用程序中重要的组件之一,常听到的android四大组件是Activity.Service.BroadcastReceiver和ContentProvider.它间接继 ...

  4. 使用active mq

    1 windows下使用active mq 1.1 下载active mq 1.2 点击根目录\bin\win64\activemq.bat运行 1.3 登陆查看 http://localhost:8 ...

  5. SecureCRT 会话设置项

    登陆动作------自动登陆仿真------两个颜色复选框都勾上模式------光标键模式(2个复选框)映射键------使用windows复制和粘贴热键外观------字符编码:UTF-8外观--- ...

  6. FI模块与SD、MM的接口配置方法

    [转自 http://blog.itpub.net/195776/viewspace-1023910/] 1 FI/SD 借口配置FI/SD通过tcode VKOA为billing设置过帐科目,用户可 ...

  7. pandas,apply并行计算的一个demo

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2018-10-11 17:55:26 # @Author : Sheldon (thi ...

  8. 登录令牌 Token 介绍

     Token值介绍 token 值: 登录令牌.利用 token 值来判断用户的登录状态.类似于 MD5 加密之后的长字符串. 用户登录成功之后,在后端(服务器端)会根据用户信息生成一个唯一的值.这个 ...

  9. JAVA各版本更新特性1-8

    JAVA各版本更新特性1-8 原文地址 Java Versions, Features and History This article gives you a highlight of import ...

  10. 吴恩达机器学习笔记(十二) —— Application Example: Photo OCR(完)

    主要内容: 一.Photo OCR 二.Getting lots of data:artificial data synthesis 三.Ceiling analysis 一.Photo OCR Ph ...