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 (1≤n≤1000001≤n≤100000, 2≤k≤1000002≤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 (1≤ai≤1091≤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)扫一下就好了。

 #include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){return b==?a:gcd(b,a%b);}
set<long long >S;
int main(){
long long a,n,k,i,j,g=;
cin>>n>>k;
for(i=;i<=n;++i){
cin>>a;
g=gcd(g,a);
}
for(i=,j=;j<=k;j++,i+=g) S.insert(i%k);
cout<<S.size()<<endl;
for(set<long long >::iterator it=S.begin();it!=S.end();++it){
printf("%lld%c",*it,it==S.end()?'\n':' ');
}
return ;
}

CF-499div2-E-裴蜀定理的更多相关文章

  1. 【BZOJ-2299】向量 裴蜀定理 + 最大公约数

    2299: [HAOI2011]向量 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1118  Solved: 488[Submit][Status] ...

  2. 【BZOJ-1441】Min 裴蜀定理 + 最大公约数

    1441: Min Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 471  Solved: 314[Submit][Status][Discuss] De ...

  3. BZOJ-2257 瓶子和燃料 分解因数+数论方面乱搞(裴蜀定理)

    一开始真没想出解法...后来发现那么水.... 2257: [Jsoi2009]瓶子和燃料 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 970 So ...

  4. 【BZOJ】1441: Min(裴蜀定理)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1441 这东西竟然还有个名词叫裴蜀定理................ 裸题不说....<初等数 ...

  5. BZOJ 2257: [Jsoi2009]瓶子和燃料 裴蜀定理

    2257: [Jsoi2009]瓶子和燃料 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...

  6. BZOJ 2257: [Jsoi2009]瓶子和燃料【数论:裴蜀定理】

    2257: [Jsoi2009]瓶子和燃料 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1326  Solved: 815[Submit][Stat ...

  7. 【Wannafly挑战赛22A计数器】【裴蜀定理】

    https://www.nowcoder.com/acm/contest/160/A 题目描述 有一个计数器,计数器的初始值为0,每次操作你可以把计数器的值加上a1,a2,...,an中的任意一个整数 ...

  8. [BZOJ 2299][HAOI 2011]向量 题解(裴蜀定理)

    [BZOJ 2299][HAOI 2011]向量 Description 给你一对数a,b,你可以任意使用(a,b), (a,-b), (-a,b), (-a,-b), (b,a), (b,-a), ...

  9. hdu 6444 网络赛 Neko's loop(单调队列 + 裴蜀定理)题解

    题意:有编号为0~n-1的n个游戏,每个活动都有一个价值(可为负),给你m,s和k,你可以从任意一个编号开始玩,但是下一个游戏必须是编号为(i + k)%n的游戏,你最多能玩m次游戏,问你如果最后你手 ...

  10. 【裴蜀定理】【CF1091C】 New Year and the Sphere Transmission

    Description 有 \(n\) 个人围成一个圈,按照顺时针从 \(1\) 到 \(n\) 编号.第 \(1\) 个人会拿到一个球,他指定一个数字 \(k\),然后会将球传给他后面顺指针数第 \ ...

随机推荐

  1. python3.4学习笔记(十六) windows下面安装easy_install和pip教程

    python3.4学习笔记(十六) windows下面安装easy_install和pip教程 easy_install和pip都是用来下载安装Python一个公共资源库PyPI的相关资源包的 首先安 ...

  2. Q_DECLARE_PRIVATE与Q_DECLARE_PUBLIC

    Q_DECLARE_PRIVATE与Q_DECLARE_PUBLIC 这两个宏在Qt的源码中随处可见,重要性不言而喻.在 部落格的 Inside Qt Series 系列文章中,他用了3篇文章来讲这个 ...

  3. SpringMVC Spring MyBatis 框架整合 Annotation MavenProject

    项目结构目录 pom.xml   jar包管理 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&q ...

  4. Linux中tomcat日志按日期自动分割

    Linux中tomcat日志分割需要用到cronolog 附上cronolog-1.6.2.tar.gz 1. 安装cronolog tar –zxvf cronolog-1.6.2.tar.gz . ...

  5. Metasploit应用举例

    本篇文章包含以下几方面内容: 1.Metasploit端口扫描: 2.用其他模块 3.metasploit smb获取系统信息 4.Metsploit服务识别 5.ftp识别: 6.metasploi ...

  6. python中的迭代器和生成器学习笔记总结

    生成器就是一个在行为上和迭代器非常类似的对象.   是个对象! 迭代,顾名思意就是不停的代换的意思,迭代是重复反馈过程的活动,其目的通常是为了逼近所需目标或结果.每一次对过程的重复称为一次“迭代”,而 ...

  7. 2016年蓝桥杯B组C/C++省赛(预选赛)题目解析

    2016年蓝桥杯B组C/C++ 点击查看2016年蓝桥杯B组省赛试题(无答案版) 第一题:煤球数目 题解 有一堆煤球,堆成三角棱锥形.具体: 第一层放1个, 第二层3个(排列成三角形), 第三层6个( ...

  8. [Shiro] - shiro之SSM中的使用

    在学习shiro的途中,在github发现了一个开源项目,所需的控件刚好是自己要学习的方向. 虽然还要学习完ssm的shiro与springboot的shiro,以及接下来的种种控件和类库,但学习这个 ...

  9. 如何解决Visual Studio2010 编译时提示系统找不到指定文件问题

    前一段时间,开始使用vs2010编写程序,可是在编译的时候总是报错,提示系统找不到指定文件,导致无法正常运行程序,花了好久时间终于找到原因解决,是因为常规的输出目录 要与链接的常规的输出文件要相对应. ...

  10. 【Android实验】 UI设计-ListView

    目录 实验目的 实验要求 实验内容 实现效果 实验代码 实验总结 实验目的 学习使用ListView 学习使用menu 实验要求 实现一个列表,其中显示班级学号姓名,提供添加功能,如需要删去某一项,长 ...