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还可 ...
随机推荐
- 线性代数之——微分方程和 exp(At)
本节的核心是将常系数微分方程转化为线性代数问题. \[\frac{du}{dt}=\lambda u \quad 的解为 \quad u(t) = Ce^{\lambda t}\] 代入 \(t=0\ ...
- ZOJ 2532 Internship(最大流找关键割边)
Description CIA headquarter collects data from across the country through its classified network. Th ...
- 搭建备份到业务迁移---mysql
mysql安装启动以及配置 使用到阿里云主机直接yum安装以及配置 [root@yunwei-169 mysql]# yum install mysql mysql-server [root@yunw ...
- 第二十一次ScrumMeeting会议
第二十一次Scrum Meeting 时间:2017/12/11 地点:SPR咖啡馆 人员:王子铭 游心 解小锐 王辰昱 李金奇 杨森 陈鑫 赵晓宇 照片: 目前工作进展 名字 今日 明天的工作 蔡帜 ...
- spring 国际化i18n配置
i18n(其来源是英文单词 internationalization的首末字符i和n,18为中间的字符数)是“国际化”的简称.在资讯领域,国际化(i18n)指让产品(出版物,软件,硬件等)无需做大的改 ...
- 《JavaScript 高级程序设计》总结
一.JS基本概念 1.命名规则 变量名区分大小写(test和Test是两个不同的变量名),标识符采用驼峰命名格式,即:第一个字母小写,剩下的每个有意义的单词首字母大写: 标识符第一个字符必须是以字母. ...
- P4语法(1)基础数据类型和Header
文章学习自:P4语言编程详解 由于原文有一点的年份,所以也继续阅读了相关的最新规范. P4语言规范 基础数据类型 布尔型(bool) 运算符 描述 and 双目运算符,结果为布尔型 or 双目运算符, ...
- Java中的增强for循环
增强 for 循环 1. 增强的 for 循环对于遍历 Array 或 Collection 的时候相当方便. import java.util.*; public class Test { publ ...
- ACM 第八天
数据结构和算法目录表 数据结构和算法目录表 C C++ Java 线性结构 1. 数组.单链表和双链表 2. Linux内核中双向链表的经典实现 数组.单链表和双链表 数组.单链表和双链表 ...
- windows批处理学习(for和字符串)---03
[1]for命令简介 先把for循环与for命令类比一下,这样学习理解快. for 循环语句,一般格式如下: 1 for (表达式1;表达式2;表达式3) 2 { 3 循环体; 4 } 1. 表达式1 ...