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. C# 汉字转拼音(转)

    (一)将汉字转化成全拼代码: private void button1_Click(object sender, EventArgs e) { this.textBox2.Text = Hz2Py.C ...

  2. 为ProgressBar进度条设置颜色1

    可以通过xml文件来设置,方法如下: 1:先在布局文件中的ProgressBar加入下面属性: android:progressDrawable="@drawable/progress_ba ...

  3. RichTextBox 自动滚动到最后

    RichTextBox.AppendText($"[{DateTime.Now.ToString("hh:mm:ss")}] {msg}\n"); RichTe ...

  4. C# new的用法

    在 C# 中,new 关键字可用作运算符.修饰符或约束. 1)new 运算符:用于创建对象和调用构造函数.这种大家都比较熟悉,没什么好说的了. 2)new 修饰符:在用作修饰符时,new 关键字可以显 ...

  5. opencv的初体验

    http://guoming.me/opencv-config  这篇文章有讲解opencv的安装与配置 一些常用库 opencv_core249d.lib opencv_imgproc249d.li ...

  6. ios应用启动后的自动版本检测方式

    今天意外的发现了appstore居然还提供通过url获取json格式的客户端信息链接: http://itunes.apple.com/lookup?id=$id 通过此地址可以获取应用的icon.介 ...

  7. npm,grunt,less,sass,typescript

    typescript   http://www.typescriptlang.org sass   http://sass-lang.com/ less http://lesscss.org/ bow ...

  8. STL学习一:标准模板库理论基础

    STL(Standard Template Library,标准模板库)是惠普实验室开发的一系列软件的统称.现然主要出现在C++中,但在被引入C++之前该技术就已经存在了很长的一段时间. STL的从广 ...

  9. HTML & XML 转义字符

    HTML & XML 转义字符 HTML中<, >,&等有特殊含义,(前两个字符用于链接签,&用于转义),不能直接使用.使用这三个字符时,应使用它们的转义序列,如下 ...

  10. SCRUM团队的三个角色

    Scrum团队中包括三个角色,他们分别是产品负责人.开发团队和 Scrum Master. Scrum 团队是自组织.跨职能的完整团队.自组织团队决定如何最好地完成他们的工作,而不是由团队外的其他人来 ...