zoukankan      html  css  js  c++  java
  • E. Border

    E. Border
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.

    There are nn banknote denominations on Mars: the value of ii-th banknote is aiai. Natasha has an infinite number of banknotes of each denomination.

    Martians have kk fingers on their hands, so they use a number system with base kk. In addition, the Martians consider the digit dd (in the number system with base kk) divine. Thus, if the last digit in Natasha's tax amount written in the number system with the base kk is dd, the Martians will be happy. Unfortunately, Natasha does not know the Martians' divine digit yet.

    Determine for which values dd Natasha can make the Martians happy.

    Natasha can use only her banknotes. Martians don't give her change.

    Input

    The first line contains two integers nn and kk (1n1000001≤n≤100000, 2k1000002≤k≤100000) — the number of denominations of banknotes and the base of the number system on Mars.

    The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai1091≤ai≤109) — denominations of banknotes on Mars.

    All numbers are given in decimal notation.

    Output

    On the first line output the number of values dd for which Natasha can make the Martians happy.

    In the second line, output all these values in increasing order.

    Print all numbers in decimal notation.

    Examples
    input
    Copy
    2 8
    12 20
    output
    Copy
    2
    0 4
    input
    Copy
    3 10
    10 20 30
    output
    Copy
    1
    0
    Note

    Consider the first test case. It uses the octal number system.

    If you take one banknote with the value of 1212, you will get 148148 in octal system. The last digit is 4848.

    If you take one banknote with the value of 1212 and one banknote with the value of 2020, the total value will be 3232. In the octal system, it is 408408. The last digit is 0808.

    If you take two banknotes with the value of 2020, the total value will be 4040, this is 508508 in the octal system. The last digit is 0808.

    No other digits other than 0808 and 4848 can be obtained. Digits 0808 and 4848 could also be obtained in other ways.

    The second test case uses the decimal number system. The nominals of all banknotes end with zero, so Natasha can give the Martians only the amount whose decimal notation also ends with zero.

     数论题目 

    给出n种钞票的面值(十进制下),每种钞票数量INF,

    问在k进制下能组合成的所有面额的最低位的数有哪些。

    这就等价于是  a1*x1+a2*x2+......+an*xn=g  ,g就是组合成的钞票面值,

    由裴蜀定理可知d=y*gcd(a1,a2,,,an),

    我们只要求出gcd(a1,a2,,,,,,an),然后把所有情况(y<k)扫一下就好了。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 1e5 + 10;
     4 const int mod = 1e9 + 7;
     5 typedef long long LL;
     6 set<LL>st;
     7 LL n, k, x, cnt = 0;
     8 int main() {
     9     cin >> n >> k;
    10     while(n--) {
    11         cin >> x;
    12         cnt = __gcd(x, cnt);
    13     }
    14     for (LL i = 0, j = 0 ; i <= k ; j += cnt, i++)
    15         st.insert(j % k);
    16     printf("%d
    ", st.size());
    17     set<LL>::iterator it;
    18     for ( it = st.begin() ; it != st.end() ; it++ ) {
    19         printf("%lld ", *it);
    20     }
    21     printf("
    ");
    22     return 0;
    23 }
  • 相关阅读:
    MySQL表的各种类型
    MySQL的慢查询使用与分析
    推荐一款Windows下的桌面倒数日软件
    C语言 复习指南
    C语言函数指针、回调函数
    VSCode环境配置 for C and C++
    JAVA编程基础&面试题
    MarkDown支持的十六进制颜色列表
    短路运算符、位运算总结
    Let's Encrypt的HTTPS证书在阿里云OSS内部署
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/9377444.html
Copyright © 2011-2022 走看看