XTU1199:Number Game

题目描述

给你一个有N个数的集合S和一个数X,判断是否存在S的一个子集,子集里的数的最小公倍数正好是X。

输入

第一行是数据组数T。 接下来有多组数据,每组数据包含两行: 第一行有2个数N和X,1<=N<=100000 ,X<=10^9。 第二行给出N个数,1<=S[i]<=10^9。

输出

对于每一组数据,输出一行"Case #X: Y",X是第几组数据,Y是Yes或No。

样例输入

2
4 20
2 3 4 5
3 61
3 4 5

样例输出

Case #1: Yes
Case #2: No

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define ll __int64
ll a[100005],p[100005],len;

ll gcd(ll a,ll b)
{
    if(b)
        return gcd(b,a%b);
    else return a;

}

int main()
{
    ll t,n,x,i,j,r,cas = 1,sum;
    scanf("%I64d",&t);
    while(t--)
    {
        scanf("%I64d%I64d",&n,&x);
        sum = 1;
        for(i = 0; i<n; i++)
        {
            scanf("%I64d",&a[i]);
            sum = (sum*a[i])%x;
        }
        printf("Case #%d: ",cas++);
        if(sum%x)
            printf("No\n");
        else
        {
            int flag = 0;
            len = 0;
            for(i = 0; i<n; i++)
            {
                if(x%a[i] == 0)
                    p[len++] = a[i];
            }
            ll ans = 1;
            for(i = 0; i<len; i++)
            {
                if(ans<p[i])
                    ans = (ans*p[i])/gcd(p[i],ans);
                else
                    ans = (ans*p[i])/gcd(ans,p[i]);
                if(ans==x)
                {
                    flag = 1;
                    break;
                }
            }
            if(flag)
                printf("Yes\n");
            else
                printf("No\n");
        }
    }

    return 0;
}

XTU1199:Number Game

时间: 2025-01-08 05:00:34

XTU1199:Number Game的相关文章

HDU4952:Number Transformation

Problem Description Teacher Mai has an integer x. He does the following operations k times. In the i-th operation, x becomes the least integer no less than x, which is the multiple of i. He wants to know what is the number x now. Input There are mult

前端(十四)—— JavaScript基础:Number、Date类、字符串、数组、Math类、正则

JS常用类:Number类.Date类.Math类.字符串.数组.正则 一.Number 1.常用数字 整数:10 小数:3.14 科学计数法:1e5 | 1e-5 正负无穷:Infinity | -Infinity 2.常用进制 二进制:0b1010 以0b开头 八进制:012 以0开头 十进制:10 十六进制:0xA 以0x开头 3.NaN 非数字类型,通过isNaN()进行判断 4.常用常量 最大值:MAX_VALUE(1.7976931348623157e+308) 最小值:MIN_VA

LeetCode OJ:Number of 1 Bits(比特1的位数)

Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011, so the function should retu

LeetCode 191:number of one bits

题目就是: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011, so the function shoul

LeetCode OJ:Number of Islands(孤岛计数)

Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by

LeetCode:Number of 1 Bits - 整数的汉明重量

1.题目名称 Number of 1 Bits(整数的汉明重量) 2.题目地址 https://leetcode.com/problems/number-of-1-bits/ 3.题目内容 英文:Write a function that takes an unsigned integer and returns the number of '1' bits it has. 中文:写一个函数,输入一个无符号整数,返回其中值为1的比特位的个数(这个值也被称为数字汉明重量) 例如,32位整型数字11

LeetCode(476): Number Complement

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. Note: The given integer is guaranteed to fit within the range of a 32-bit signed integer. You could assume no leading ze

2017 ACM/ICPC Asia Regional Shenyang Online:number number number hdu 6198【矩阵快速幂】

Problem Description We define a sequence F: ? F0=0,F1=1;? Fn=Fn?1+Fn?2 (n≥2). Give you an integer k, if a positive number n can be expressed byn=Fa1+Fa2+...+Fak where 0≤a1≤a2≤?≤ak, this positive number is mjf?good. Otherwise, this positive number is 

三个把值转换成数值类型的函数:Number()、 parseInt()、 parseFloat()的区别

一 .Number() Number()可以把任意值转换成数值,如果要转换的字符串中有一个不是数值的字符,返回NaN 例如: var num1 = Number(true); //true返回1 false返回0 var num2 = Number(undefined); //返回NaN var num3 = Number("hello"); //返回NaN var num4 = Number(" "); //如果是空字符串返回0 var num5 = Number