zoukankan      html  css  js  c++  java
  • CodeForces 688D-Remainders Game

    题意:
      已知n, k与n个整数(c1,c2,...,cn),问你是否存在一个数x,使得它能被n个整数且k整除.

    分析:
      可以先将n个整数的最小公倍数lcm计算出来,再判断它是否能被k整除.

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <fstream>
     5 #include <ctime>
     6 #include <cmath>
     7 #include <cstdlib>
     8 #include <algorithm>
     9 #include <set>
    10 #include <map>
    11 #include <list>
    12 #include <stack>
    13 #include <queue>
    14 #include <iterator>
    15 #include <vector>
    16 
    17 using namespace std;
    18 
    19 #define LL long long
    20 #define INF 0x3f3f3f3f
    21 #define MOD 1000000007
    22 #define MAXN 10000010
    23 #define MAXM 1000010
    24 
    25 
    26 LL gcd(LL m, LL n)
    27 {
    28     LL a, b;
    29     a = m;
    30     b = n;
    31     if(a < b)
    32     {
    33         LL temp;
    34         temp = a;
    35         a = b;
    36         b = temp;
    37     }
    38     while(b != 0)
    39     {
    40         LL temp;
    41         temp = a%b;
    42         a = b;
    43         b = temp;
    44     }
    45     return a;
    46 }
    47 
    48 LL lcm(LL x, LL y)
    49 {
    50     return x/gcm(x, y)*y;
    51 }
    52 
    53 int main()
    54 {
    55     int n, k;
    56     LL ans, m;
    57     while(scanf("%d%d", &n, &k)==2)
    58     {
    59         int i;
    60         ans = 1;
    61         for(i = 1; i <= n; i++ )
    62         {
    63             scanf("%lld", &m);
    64             ans = lcm(ans, m)%k;
    65         }
    66         if(ans == 0)
    67             printf("Yes
    ");
    68         else
    69             printf("No
    ");
    70     }
    71 
    72     return 0;
    73 }
  • 相关阅读:
    驱动Makefile
    ioremap
    file结构体
    Python基础-语法知识
    企业运营对 DevOps 的「傲慢与偏见」
    漂亮得不像实力派!
    如何用 OneAPM 优化你的 Node.js 应用?
    全球说:要给 OneAlert 点100个赞
    DevOps 和技术债务偿还自动化
    PHP 性能分析与实验(二)——PHP 性能的微观分析
  • 原文地址:https://www.cnblogs.com/xl1164191281/p/5669731.html
Copyright © 2011-2022 走看看