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. WebService 简单应用

    Web服务全称:XML Web Service,是一种可编程的应用程序逻辑组件,它可以在Internet或企业网的Web应用程序之间共享.Web服务被设计成能够通过Internet与其它应用程序之间直 ...

  2. 远程访问(HttpClient和HttpResponse的使用) 原型模式

    package com.webserver.webservice; import java.io.ByteArrayInputStream; import java.io.FileOutputStre ...

  3. win10+UEFI下u盘安装ubuntu16.04

    本人电脑是华硕,由于要求使用linux所以安装: 1.首先给linux划出一个大分区,感觉最少50G: win10下磁盘管理,在最后的分区中压缩出50g,空间,其他的不用问了,也不用继续分区,一个大的 ...

  4. BZOJ2539: [Ctsc2000]丘比特的烦恼

    BZOJ2539: [Ctsc2000]丘比特的烦恼 Description 随着社会的不断发展,人与人之间的感情越来越功利化. 最近,爱神丘比特发现,爱情也已不再是完全纯洁的了. 这使得丘比特很是苦 ...

  5. gitPermission denied (publickey).

    $ git clone git@github.com:DavidWanderer/test1.git Cloning into 'test1'... Warning: Permanently adde ...

  6. angularJs自定义模块

    <script type="text/javascript"> var myApp = angular.module("myApp",[]); my ...

  7. RaspBerry Pi3 ~ 内核编译

    RaspBerryPi3-内核编译 转载注明出处:http://www.cnblogs.com/einstein-2014731/p/5985128.html 在有道云笔记的同步分享:http://n ...

  8. Git如何强制拉取一个远程分支到本地分支(转载)

    有时候,我们在使用git pull指令想把一个远程分支拉取到本地分支的时候,老是会拉取失败,这一般是因为某种原因,本地分支和远程分支的内容差异无法被git成功识别出来,所以git pull指令什么都不 ...

  9. Android Studio快速添加Gson Gsonformat

    一.Android Studio快速添加Gson 具体操作:       1.File->Project Structure: 2.app->Dependencies->" ...

  10. 7-4 汉密尔顿回路(25 分) 【STL】

    7-4 汉密尔顿回路(25 分) 著名的"汉密尔顿(Hamilton)回路问题"是要找一个能遍历图中所有顶点的简单回路(即每个顶点只访问 1 次).本题就要求你判断任一给定的回路是 ...