[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 ...
随机推荐
- Centos6.4版本下搭建LAMP环境
Centos6.4版本下搭建LAMP环境 配置yum mkdir/mnt/cdrom mount/dev/cdrom /mnt/cdrom 装载光盘 vi /etc/yum.repos.d/Cent ...
- net 中捕获摄像头视频的方式及对比(How to Capture Camera Video via .Net) (转)
作者:王先荣前言 随着Windows操作系统的不断演变,用于捕获视频的API接口也在进化,微软提供了VFW.DirectShow和MediaFoundation这 三代接口.其中VFW早已被Di ...
- AngularJS(17)-Angular小程序
现在可以开始创建您的第一个 AngularJS 应用程序,一个 AngularJS 单页 Web 应用. <!DOCTYPE html> <html lang="en&qu ...
- WPF:实现主应用程序单一实例运行方式总结
本文介绍常见的实现主应用程序单一实例运行的几种方式. 方式一: public partial class App : Application { protected override void ...
- 如何保持iOS上键盘出现时输入框不被覆盖
在 iOS5 上请求显示键盘时,系统从屏幕底部将键盘滑入上来,位于应用的内容之上. (墙内:http://mikixiyou.iteye.com/blog/1488302) 如果屏幕中的内容项目比较多 ...
- 【BZOJ 1026】 [SCOI2009]windy数
Description windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道,在A和B之间,包括A和B,总共有多少个windy数? In ...
- 从一个新手容易混淆的例子简单分析C语言中函数调用过程
某天,王尼玛写了段C程序: #include <stdio.h> void input() { int i; ]; ; i < ; i++) { array[i] = i; } } ...
- Jenkins部署.NET网站项目
Jenkins Jenkins是一个开源软件项目,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能. Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括: 持 ...
- Problem 1014 xxx游戏 暴力+拓扑排序
题目链接: 题目 Problem 1014 xxx游戏 Time Limit: 1000 mSec Memory Limit : 32768 KB 问题描述 小M最近很喜欢玩XXX游戏.这个游戏很简单 ...
- JS中删除字符串中的空格
问题描述: 在进行字符串操作时,由于字符串中存在较多的空格,因此需要考虑取消字符串中的空格 问题解决: (1)删除字符串中的前导空格(字符串的前面的空格): 注意:这里使用 ...