E. Border
1 second
256 megabytes
standard input
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.
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.
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.
2 8
12 20
2
0 4
3 10
10 20 30
1
0
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;
const int maxn = 1e5 + ;
const int mod = 1e9 + ;
typedef long long LL;
set<LL>st;
LL n, k, x, cnt = ;
int main() {
cin >> n >> k;
while(n--) {
cin >> x;
cnt = __gcd(x, cnt);
}
for (LL i = , j = ; i <= k ; j += cnt, i++)
st.insert(j % k);
printf("%d\n", st.size());
set<LL>::iterator it;
for ( it = st.begin() ; it != st.end() ; it++ ) {
printf("%lld ", *it);
}
printf("\n");
return ;
}
E. Border的更多相关文章
- 理解CSS边框border
前面的话 边框是CSS盒模型属性中默默无闻的一个普通属性,CSS3的到来,但得边框属性重新焕发了光彩.本文将详细介绍CSS边框 基础样式 边框是一条以空格分隔的集合样式,包括边框粗细(边框宽度 ...
- css样式之border
border用法详解: 1.border-width 属性设置边框的宽度 可能的值:像素 2.border-style 属性设置边框的样式 可能的值:solid(直线),dashed(虚线),dott ...
- 通过CSS的border绘制三角形
通过css的border 可以绘制出三角形, 不同的样式组合,有着不同的效果,可以控制它的大小,颜色,方向.看下面各种图形,相信可能还有很多图形,大家都没见过. 先写出公共的样式: .border { ...
- css3学习--border
http://blog.sina.com.cn/s/blog_61671b520101gelr.html border-radius border-radius: 50px 20px;上下都是50px ...
- border:none 和border:0区别差异
border:none与border:0的区别体现为两点:一是理论上的性能差异,二是浏览器兼容性的差异. 性能差异: [border:0;]把border设为“0”像素效果等于border-width ...
- WPF 通过Border来画边框
WPF有自己的表格控件DataGrid.ListBox等,如果只是简单的需求,可以通过Border控件来画边框. 比如我们需要给上面的控件加上边框. <Window x:Class=" ...
- css border属性做小三角标
<!doctype html><html> <head> <title></title> <meta charset="ut ...
- 使用border做三角形
网站上经常会使用一些三角形,除了图片的方式,实际上利用border我们可以做出纯CSS的三角形.我们知道border是个边抖可以单独设置,当四个边相交的时候他们是什么时候改变的? .t0{ margi ...
- iPhone 6/plus iOS Safari fieldset border 边框消失
问题:iPhone6 plus 手机浏览网页,fieldset border 边框消失. 示例代码: <div> <fieldset style="border: 1px ...
- 原来css中的border还可以这样玩
原来css中的border还可以这样玩 前面的话: 在看这篇文章之前你可能会觉得border只是简单的绘制边框,看了这篇文章,我相信你也会跟我一样说一句"我靠,原来css中的border还可 ...
随机推荐
- JAVA基础学习之路(八)[1]String类的基本特点
String类的两种定义方式: 直接赋值 通过构造方法赋值 //直接赋值 public class test2 { public static void main(String args[]) { S ...
- Image控件显示以byte[]字节数组形式存在的图片
工作中遇到了这样的一个问题.起初觉得很简单,获得了图片的byte[]后,可以将其转换成内存中的图片对象(如System.Drawing.Image),而后赋给页面的Image控件.尝试后才发现这样根本 ...
- Docker学习笔记总结
Docker学习笔记 https://yeasy.gitbooks.io/docker_practice/content/ 一 环境搭建 Ubuntu安装 .添加软件源的GPG密钥 curl -f ...
- [C++] Copy Control (part 1)
Copy, Assign, and Destroy When we define a class, we specify what happens when objects of the class ...
- Oil Deposits(DFS连通图)
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- 字符串数组去重 ["a","b","c","a","b","c"] --> ["a","b","c"]
非正则实现: let str_arr=["a","b","c","a","b","c&qu ...
- 【.NET】- Task.Run 和 Task.Factory.StartNew 区别
Task.Run 是在 dotnet framework 4.5 之后才可以使用, Task.Factory.StartNew 可以使用比 Task.Run 更多的参数,可以做到更多的定制. 可以认为 ...
- phpcms 模型
- return 返回字符串
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- WriteLine(ls.ToString());Console.WriteLine(ls);输出结果相同,为什么要加 .ToString()
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test ...