【Codeforces Round #499 (Div. 2) E】Border
【链接】 我是链接,点我呀:)
【题意】
给你n个数字,每个数字可以无限用,每种方案可以组成一个和,问你%k的结果有多少种不同的结果。
【题解】
相当于给你一个方程
$x_1*a_1+x_2*a_2+...+x_n*a_n=c$
然后根据裴蜀定理
设a1,a2,a3......an为n个整数,d是它们的最大公约数,那么存在整数x1......xn使得x1*a1+x2*a2+...xn*an=d
c只能为d的倍数。
因为把那个式子两边同乘上倍数就能构造出i*d了
可能会有些xi
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define res(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std;
const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 1e5;
int n,k,a[N+10],g;
int flag[N+10];
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> k;
for (int i = 1;i <= n;i++) cin >> a[i];
g = a[1];
for (int i = 2;i <= n;i++) g = __gcd(g,a[i]);
for (int s = 0,i = 1;i <= k;s = (s+g)%k,i++) flag[s] = 1;
int cnt = 0;
for (int i = 0;i <k;i++) if (flag[i]) cnt++;
cout<<cnt<<endl;
for (int i = 0;i < k;i++) if (flag[i]) cout<<i<<' ';
return 0;
}
【Codeforces Round #499 (Div. 2) E】Border的更多相关文章
- 【Codeforces Round #499 (Div. 1) B】Rocket
[链接] 我是链接,点我呀:) [题意] 让你猜到火星的距离x是多少. 已知1<=x<=m 然后你可以问系统最多60个问题 问题的形式以一个整数y表示 然后系统会回答你3种结果 -1 x& ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
- 【Codeforces Round #422 (Div. 2) D】My pretty girl Noora
[题目链接]:http://codeforces.com/contest/822/problem/D [题意] 有n个人参加选美比赛; 要求把这n个人分成若干个相同大小的组; 每个组内的人数是相同的; ...
随机推荐
- FreeMarker 页面静态化解决方案
一.网页的静态化方案 1.生成静态页面的时机:在做添加操作时,同时生成该新增内容的对应的静态页面 2.静态页面的名称:内容 id + ".html" 3.静态页面所在的路径:工程外 ...
- @Autowired 作用范围
一.@AutoWired 可以作用于:构造器.方法.参数.属性 二.作用在方法上 @Component public class Student{ private Book book; public ...
- OA项目知识总结2
BaseAction的抽取 项目中的每个实体类都对应一个action 每个action都都要继承ActionSupport类 已以及实现ModelDriver接口 并且需要注入service 虽然 ...
- HTTP中的重定向和请求转发的区别(转)
时间长有些忘了,转篇文章加深一下印象: 一.调用方式 我们知道,在servlet中调用转发.重定向的语句如下:request.getRequestDispatcher("new.jsp&qu ...
- plsql里面执行正常,java运行报ORA-01722: 无效数字
贴代码: <select id="getInfo" parameterClass="java.util.HashMap" resultClass=&quo ...
- linux下sort对中文排序
http://blog.csdn.net/luoleicn/article/details/6162358 设置: export LC_ALL=C;
- NYOJ 589 糖果
糖果 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 topcoder工作室的PIAOYIi超级爱吃糖果.如今他拥有一大堆不同种类的糖果.他准备一口气把它们吃完.但是 ...
- codeforces Towers 题解
Little Vasya has received a young builder's kit. The kit consists of several wooden bars, the length ...
- Codeforces Round #260 (Div. 1) 455 A. Boredom (DP)
题目链接:http://codeforces.com/problemset/problem/455/A A. Boredom time limit per test 1 second memory l ...
- 【POJ 2481】 Cows
[题目链接] http://poj.org/problem?id=2481 [算法] 树状数组 注意特判两头牛的s,e值相同 [代码] #include <algorithm> #incl ...