Codeforces 1011E
作者:互联网
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.
InputThe 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.
OutputOn 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 Copy2 8output Copy
12 20
2input Copy
0 4
3 10output Copy
10 20 30
1
0
题意
(a1x+a2y+a3z+……..anw ) %k的种类数
思路:
我们知道 a1x+a2y+a3z+……..anw = d 当且仅当gcd(a1,a2,a3,…an) | d
所以这题等价于 (xgcd(a1,a2,a3,…an))%k 的种类数 枚举下就行
#include<iostream> #include<cstdio> #define maxn 100010 using namespace std; int n,mod,a[maxn]; bool vis[maxn]; int gcd(int x,int y){ if(y==0)return x; else return gcd(y,x%y); } int main(){ scanf("%d%d",&n,&mod); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=2;i<=n;i++) a[i]=gcd(a[i],a[i-1]); int ans=0; for(int i=1;i<=mod;i++){ int now=1LL*i*a[n]%mod; if(!vis[now]){ vis[now]=1; ans++; } } printf("%d\n",ans); for(int i=0;i<=mod;i++){ if(vis[i])printf("%d ",i); } puts(""); return 0; }
标签:Martians,int,1011E,number,Codeforces,Mars,output,Natasha 来源: https://www.cnblogs.com/thmyl/p/12181417.html