Border Codeforces Round #499 (Div. 2) (數論)
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 n
banknote denominations on Mars: the value of i-th banknote is ai
. Natasha has an infinite number of banknotes of each denomination.
Martians have k
fingers on their hands, so they use a number system with base k. In addition, the Martians consider the digit d (in the number system with base k) divine. Thus, if the last digit in Natasha’s tax amount written in the number system with the base k is d
, the Martians will be happy. Unfortunately, Natasha does not know the Martians’ divine digit yet.
Determine for which values d
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 n
and k (1≤n≤100000, 2≤k≤100000
) — the number of denominations of banknotes and the base of the number system on Mars.
The second line contains n
integers a1,a2,…,an (1≤ai≤109
) — denominations of banknotes on Mars.
All numbers are given in decimal notation.
Output
On the first line output the number of values d
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 12
, you will get 148 in octal system. The last digit is 48
.
If you take one banknote with the value of 12
and one banknote with the value of 20, the total value will be 32. In the octal system, it is 408. The last digit is 08
.
If you take two banknotes with the value of 20
, the total value will be 40, this is 508 in the octal system. The last digit is 08
.
No other digits other than 08
and 48 can be obtained. Digits 08 and 48
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.
題意
(a1x+a2y+a3z+……..anw ) %k的種類數
思路:
我們知道 a1x+a2y+a3z+……..anw = d 當且僅當gcd(a1,a2,a3,…an) | d
所以這題等價於 (xgcd(a1,a2,a3,…an))%k 的種類數 列舉下就行
accode
#include<bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 1e5+32;
LL n,k;
LL a[maxn];
LL ans[maxn];
int main()
{
scanf("%lld%lld",&n,&k);
for(int i = 1;i<=n;i++){
scanf("%lld",&a[i]);
a[i]%=k;
}
LL gcd = a[1];
for(int i = 2;i<=n;i++){
gcd = __gcd(gcd,a[i]);
}
int p = 0;
ans[p++] =0;
LL now = gcd;
LL nowx = 1;
while(nowx<=k&&gcd!=0){
now=nowx*gcd%k;
if(nowx>k){break;}
ans[p++] = now;
nowx++;
}
sort(ans,ans+p);
int len = unique(ans,ans+p)-ans;
cout<<len<<endl;
for(int i = 0;i<len;i++){
printf("%lld%c",ans[i],i==len-1?'\n':' ');
}
}
相關推薦
Border Codeforces Round #499 (Div. 2) (數論)
E. Border time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ast
Codeforces Round #499 (Div. 1) C. Border || Codeforces Round #499 (Div. 2) E.Border(數論/貝祖定理)
Codeforces Round #499 (Div. 1) C. Border Codeforces Round #499 (Div. 2) E. Border
Codeforces Round #247 (Div. 2)(B)(暴力,全排列函式||DFS)
Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks. There is only
Codeforces Round #429 (Div. 2)-(DFS)
Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not
Codeforces Round #499 (Div. 2)E. Border(離散數學)
題意:給你n種紙幣,然後給你一個k,代表k進位制,意思就是求這n種紙幣的任意組合,然後mod k,能組成多少0~m-1的數字 思路:離散數學的基本知識,n個紙幣和m的最大公約數就是最小生成元,這個
AC Codeforces Round #499 (Div. 2) E. Border 擴充套件歐幾里得
沒想出來QAQ....QAQ....QAQ.... 對於一般情況,我們知道 ax+by=gcd(a,b)ax+by=gcd(a,b)ax+by=gcd(a,b) 時方程是一定有解的。 如果改成 ax+by=cax+by=cax+by=c 的話該方程有解當且僅當
Codeforces Round #324 (Div. 2) (B排列組合)(C貪心)(D哥德巴赫猜想 數論+暴力)
題意:。。。。 思路:剛開始還想用什麼字串模擬或者大數什麼的,後來想了想差點笑出聲來,樣例就是用來忽悠人的。。。 #include <bits/stdc++.h> #define ll
Codeforces Round #499 (Div. 2) E. Border
E. Border time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Astronaut
Codeforces Round #499 (Div. 2) C. Fly(java)
型別:模擬 題意:從地球起飛->星球1降落->星球1起飛->星球2起飛->······->星球n-1起飛->地球降落 題解:逆過程模擬,如果費用存在<=
Codeforces Round #499 (Div. 2) - 賽後補題
sed pri pen src target ems print cout blank C. Fly 題解:二分答案,然後模擬驗證。 //#include<bits/stdc++.h> #include<cstdio> #include<c
Codeforces Round #524 (Div. 2)(前3題題解)
這場比賽手速場+數學場,像我這樣讀題都讀不大懂的蒟蒻表示呵呵呵。 第四題搞了半天,大概想出來了,但來不及(中途家裡網炸了)查錯,於是我交了兩次丟了100分。幸虧這次沒有掉rating。 比賽傳送門:https://codeforces.com/contest/1080。 A.Petya
【CF套題】Codeforces Round #524 (Div. 2) (1080A~F)
原題地址 迴歸 CF \text {CF} CF,這場堪堪上紫。 A.Petya and Origa
Codeforces Round #185 (Div. 2)(解題報告)(ABC出DE補)
第一次抽時間做一整套的cf ,可以說是心情複雜,D,E都是什麼神仙題目啊!!! A Whose sentence is it? (水題) 題目: One day, liouzhou_101 got a chat record of Freda and Rain
Codeforces Round #499 (Div. 2) C.FLY 數學推導_逆推
我們一定要注意到油量是不滿足單調性的。 Code: #include<algorithm> #include<cstdio> #include<cstring> using namespace std; const int m
Codeforces Round #499 (Div. 2) F. Mars rover_dfs_位運算
噁心到極點,思路好想,竟然出錯出在了位運算上QAQ… Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; cons
Codeforces Round #244 (Div. 2)(強連通分量,字尾陣列)
Police headquarter is monitoring signal on different frequency levels. They have got two suspiciously encoded strings s1 and s2 from two different freque
Codeforces Round #312 (Div. 2) (第三題是位運算,好題)
分析:從0座標分開,負半軸一個數組,正半軸一個數組,來記錄果樹的左邊和數量,可以用結構體陣列來儲存資料,其中少的一個半軸上的果樹肯定會全被採光,而多的一邊樹上會多采一棵樹。 struct p{ int num,x; } p neg[105],pos[105];這樣表
Codeforces Round #439 (Div. 2)(補題) A模擬+set B 數學 C dp or 楊輝三角組合數
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii-chan! With hands joined, go everywhere at a speed fas
Codeforces Round #340 (Div. 2) (629A,629B,629C(排列組合,動態規劃),629D(線段樹))
Far Relative’s Birthday Cake 題目連結: 解題思路: Consider that we have rowi chocolates in the i'th row and coli chocolates in the i'th colum
Codeforces Round #365 (Div. 2) (703A,703B(容斥),703C(幾何),703D(樹狀陣列))
Mishka and Game 題目連結: 解題思路: In this problem you had to do use the following algo. If Mishka wins Chris in the current round, then increa