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的更多相关文章

  1. HackerRank The Chosen One [预处理][gcd]

    题解:tags:[预处理][gcd]故事背景:光头钻进了茫茫人海.这是一个典型の通过前缀后缀和来降低复杂度的问题.先用pre数组与suf数组分别维护前缀gcd和后缀gcd.如果 a[i] % gcd( ...

  2. Hackerrank GCD Product(莫比乌斯反演)

    题意 题目链接 Sol 一道咕咕咕了好长时间的题 题解可以看这里 #include<bits/stdc++.h> #define LL long long using namespace ...

  3. HackerRank# Red John is Back

    原题地址 简单动归+素数判定,没用筛法也能过 代码: #include <cmath> #include <cstdio> #include <vector> #i ...

  4. *[hackerrank]Die Hard 3

    https://www.hackerrank.com/contests/w7/challenges/die-hard-3 首先,发现c <= max(a, b) 而且 c = aX + bY时有 ...

  5. GCD 多线程

    Grand Central Dispatch (GCD)是Apple开发的一个多核编程的较新的解决方法.它主要用于优化应用程序以支持多核处理器以及其他对称多处理系统.它是一个在线程池模式的基础上执行的 ...

  6. Sherlock and GCD

    1 import fractions, functools, sys if __name__ == '__main__': T = int(sys.stdin.readline()) for _ in ...

  7. Xtreme8.0 - Play with GCD dp

    Play with GCD 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/play-with-g ...

  8. Solve Equations HackerRank 扩展欧几里德 && 数学

    https://www.hackerrank.com/contests/infinitum16-firsttimer/challenges/solve-equations 给定一条方程a*x + b* ...

  9. 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 ...

随机推荐

  1. 实现Server.UrlEncode和Server.UrlDecode功能的js代码

    <script> var EncodeURI = function(unzipStr,isCusEncode){    if(isCusEncode){        var zipArr ...

  2. (转)汉字转拼音HanziToPinyin

    本文转载于:http://blog.csdn.net/zhangphil/article/details/47164665 Android系统本身自带有有将汉字转化为英文拼音的类和方法.具体的类就是H ...

  3. TIME_WAIT引起Cannot assign requested address报错

    1.  问题描述 有时候用redis客户端(php或者java客户端)连接Redis服务器,报错:"Cannot assign requested address." 原因是客户端 ...

  4. oracle-12c-rac 报:ORA-01078

    OS: Oracle Linux Server release 5.7 DB: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - ...

  5. WPF中的Style

    一.Style基础知识 构成Style最重要的两种元素是Setter和Trigger Setter类帮助我们设置控件的静态外观风格 Trigger类帮助我们设置控件的行为风格 Setter类的Prop ...

  6. 安装Golang 1.6及开发环境

    安装Golang 1.6及开发环境=====================================> 下载软件    * go1.4.2.linux-amd64.tar.gz     ...

  7. gcc编译出现的问题

    /usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error 解决办法:g++ -std=c++11

  8. 【http】生命周期和http管道技术 整理中

    httpModules 与 httpHandlers  正在写demo public class Httpext : IHttpModule { public void Dispose() { thr ...

  9. SQL日语词汇

    データベース 数据库 DATABASE インスタンス (数据库)实例 INSTANCE ユーザー 用戶 USER ログイン・ログアウト ログオン・ログオフ 登录 LOGIN/LOGOUT LOGNO/ ...

  10. SkyDrive Pro client now available as standalone download. Hurray!

    SkyDrive Pro client now available as standalone download. Hurray! by  Todd O. Klindt  on 5/21/2013 1 ...