牛客wannaflay挑战赛22 签到题 计数器 && Wolf and Rabbit HDU 1222

这链接真特么难找

链接:https://www.nowcoder.com/acm/contest/160/A
来源:牛客网
 

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

有一个计数器,计数器的初始值为0,每次操作你可以把计数器的值加上a1,a2,...,an中的任意一个整数,操作次数不限(可以为0次),问计数器的值对m取模后有几种可能。

输入描述:

第一行两个整数n,m
接下来一行n个整数表示a1,a2,...,an
1≤n≤100
1≤m,a1,a2,...,an≤1000000000

输出描述:

输出一个整数表示答案

 

示例1

输入

复制

3 6
6 4 8

输出

复制

3

求出所有数的公共gcd,即每次可以多出多少(注意第一次要和m进行gcd)

#include <cstdio>
#include <algorithm>
#include <iostream>
 
using namespace std;
int main()
{
    int n, m, i;
    cin>>n>>m;
    int x = m;
    int a;
    for(i=0; i<n; i++){
        cin>>a;
        x = __gcd(a, x);
    }
    cout<<m/x<<endl;
     
    return 0;
}

类似思想在hdu1222http://acm.hdu.edu.cn/showproblem.php?pid=1222

解法差不多,但是这个题面更容易理解

Problem Description

There is a hill with n holes around. The holes are signed from 0 to n-1.


A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into the hole every m holes. For example, m=2 and n=6, the wolf will get into the holes which are signed 0,2,4,0. If the rabbit hides in the hole which signed 1,3 or 5, she will survive. So we call these holes the safe holes.

Input

The input starts with a positive integer P which indicates the number of test cases. Then on the following P lines,each line consists 2 positive integer m and n(0<m,n<2147483648).

Output

For each input m n, if safe holes exist, you should output "YES", else output "NO" in a single line.

Sample Input

2

1 2

2 2

Sample Output

NO YES

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int n,m;
		scanf("%d%d",&m,&n);
		if(__gcd(m,n)==1)
			puts("NO");
		else
			puts("YES");
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值