[hackerrank]John and GCD list
https://www.hackerrank.com/contests/w8/challenges/john-and-gcd-list
简单题,GCD和LCM。
#include <vector>
#include <iostream> using namespace std; int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
return gcd(b, a % b);
}
} int lcm(int a, int b) {
return a * b / gcd(a, b);
} int main() {
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<int> B(N + 1);
for (int i = 1; i < N; i++) {
B[i] = lcm(A[i], A[i - 1]);
}
B[0] = A[0];
B[N] = A[N - 1];
for (int i = 0; i <= N; i++) {
cout << B[i] << " ";
}
cout << endl;
} return 0;
}
[hackerrank]John and GCD list的更多相关文章
- HackerRank The Chosen One [预处理][gcd]
题解:tags:[预处理][gcd]故事背景:光头钻进了茫茫人海.这是一个典型の通过前缀后缀和来降低复杂度的问题.先用pre数组与suf数组分别维护前缀gcd和后缀gcd.如果 a[i] % gcd( ...
- Hackerrank GCD Product(莫比乌斯反演)
题意 题目链接 Sol 一道咕咕咕了好长时间的题 题解可以看这里 #include<bits/stdc++.h> #define LL long long using namespace ...
- HackerRank# Red John is Back
原题地址 简单动归+素数判定,没用筛法也能过 代码: #include <cmath> #include <cstdio> #include <vector> #i ...
- *[hackerrank]Die Hard 3
https://www.hackerrank.com/contests/w7/challenges/die-hard-3 首先,发现c <= max(a, b) 而且 c = aX + bY时有 ...
- GCD 多线程
Grand Central Dispatch (GCD)是Apple开发的一个多核编程的较新的解决方法.它主要用于优化应用程序以支持多核处理器以及其他对称多处理系统.它是一个在线程池模式的基础上执行的 ...
- Sherlock and GCD
1 import fractions, functools, sys if __name__ == '__main__': T = int(sys.stdin.readline()) for _ in ...
- Xtreme8.0 - Play with GCD dp
Play with GCD 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/play-with-g ...
- Solve Equations HackerRank 扩展欧几里德 && 数学
https://www.hackerrank.com/contests/infinitum16-firsttimer/challenges/solve-equations 给定一条方程a*x + b* ...
- SPOJ:Red John is Back(DP)
Red John has committed another murder. But this time, he doesn't leave a red smiley behind. What he ...
随机推荐
- CAD格式DWF嵌入到自己的网页中展示--Autodesk Design Review
网页上嵌入CAD图纸,用的 Autodesk Design Review控件嵌入IE, 网上的 dwf viewer方式没成功. Head之间 <script type="text/j ...
- table总结insertRow、deleteRow
表格有几行: var trCnt = table.rows.length; (table为Id ) 每行有几列:for (var i=0; i<trCnt; i++) ...
- php生成圆形图片
http://files.cnblogs.com/files/adtuu/circle_image.zip
- JS获取图片实际宽高及根据图片大小进行自适应
JS获取图片实际宽高,以及根据图片大小进行自适应 <img src="http://xxx.jpg" id="imgs" onload="ad ...
- windows7 64bit下安装Oracle 11g R2
Win7 bit64,安装的是64位的客户端. 1.PLSql连接数据库 (1)下载 instantclient-basic-win32-11.2.0.1.0.zip解压到Oracle要目当下 ...
- Configure Database Mirroring
使用证书配置的镜像基本安装微软次序做就可以了 http://msdn.microsoft.com/zh-cn/library/ms191140.aspx 备份还原首先要转换成完全备份模式没什么好多说的 ...
- textview点击后selector的pressed无效果
原因: 需要配置 android:clickable="true" 这个跟开发环境有关,我之前用的android studio 就不需要这一项,默认可以点击. ********* ...
- android 弹出框(输入框和选择框)
1.输入框: final EditText inputServer = new EditText(this); inputServer.setFilters(new InputFilter[]{new ...
- android camera2 Api(转载)
现在的手机一般都会提供相机功能,有些相机的镜头甚至支持1000万以上像素,有些甚至支持光学变焦,这些手机已经变成了专业数码相机.为了充分利用手机上的相机功能,Android应用可以控制拍照和录制视频. ...
- FineUI Grid控件右键菜单的实现
FineUI官方Demo上一直没有Grid右键菜单的实现,其实从4.1.x的版本开始,允许添加自定义的事件监听(Listeners),所以要实现这个功能已经相当容易了. ExtJs右键菜单有很多种,对 ...