Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
#include <iostream>
using namespace std;
int main() {
// your code goes here
long long t;
cin>>t;
while(t--){
long long n;
cin>>n;
for(int i=1; i<=n; i++){
if(i%2==0){
cout<<(i-1)*2<<" ";
}
else{
cout<<i<<" ";
}
}
cout<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
// your code goes here
long long t;
cin>>t;
while(t--){
long long n;
cin>>n;
for(int i=1; i<=n; i++){
if(i%2==0){
cout<<(i-1)*2<<" ";
}
else{
cout<<i<<" ";
}
}
cout<<endl;
}
return 0;
}
# cook your dish here
for _ in range(int(input())):
n = int(input())
ans = []
for i in range(1,n+1):
if i % 2 == 1:
ans.append(i)
elif i % 2 == 0:
ans.append((i-1)*2)
print(*ans)
#include<stdio.h>
void solve(){
int n;
scanf("%d",&n);
int a[n];
int temp = 1;
if(n == 1) {
printf("1\n");
return;
}
for(int i =0 ; i<n-1 ; i+=2) {
a[i] = temp;a[i+1] = 2*temp;temp += 2;
}
if(n%2 != 0) {a[n-1] = a[n-2] + 1;}
for(int i =0 ; i < n ; ++i) {
printf("%d ",a[i]);
}
printf("\n");
}
int main() {
int t;
scanf("%d",&t);
while(t--){
solve();
}
return 0;
}
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out));
int tt=Integer.parseInt(reader.readLine().trim());
while(tt-->0){
int n=Integer.parseInt(reader.readLine().trim());
boolean[] used=new boolean[2*n+1];
boolean isFirst=true;
for(int i=1, j=0;j<n;i++){
if(used[i]){
continue;
}
writer.write((isFirst?"":" ")+i);
used[i]=true;
j++;
isFirst=false;
if(j<n){
writer.write(" "+(2*i));
used[2*i]=true;
j++;
}
}
writer.write("\n");
}
writer.flush();
}
private static int[] parseInt(String str) {
String[] parts=str.split("\\s+");
int[] ans=new int[parts.length];
for(int i=0;i<ans.length;i++){
ans[i]=Integer.parseInt(parts[i]);
}
return ans;
}
private static long[] parseLong(String str) {
String[] parts=str.split("\\s+");
long[] ans=new long[parts.length];
for(int i=0;i<ans.length;i++){
ans[i]=Long.parseLong(parts[i]);
}
return ans;
}
}
t = int(input())
M = 10**5
u = [0 for i in range(2 * M + 1)]
a = []
x = 1
while len(a) < M:
while u[x]:
x += 1
a.append(x)
a.append(2 * x)
u[x] = 1
u[2 * x] = 1
for _ in range(t):
n = int(input())
print(*a[:n])
t = int(raw_input())
for i in range(t):
N = int(raw_input())
st = ''
v = 1
k = 0
while k < N:
k += 1
if k%2 == 1:
st += str(v) + ' '
else:
st += str(v*2) + ' '
v += 2
# endif
# endwhile
print st
# endfor i
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
using System.Numerics;
public class Test
{
public static int GetInt() => int.Parse(Console.ReadLine());
public static long GetLong() => long.Parse(Console.ReadLine());
public static int[] GetIntArray() => Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
public static long[] GetLongArray() => Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
public static string[] GetLines(int n)
{
var ans = new string[n];
for(int i=0; i<n; i++)
{
ans[i] = Console.ReadLine();
}
return ans;
}
public static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a%b);
public static int Gcd(int[] n) => n.Aggregate((a,b) => Gcd(a,b));
public static void Main()
{
var t=GetInt(); for(int i = 0; i<t; i++) { Solve(); }
// Solve();
}
public static void Solve()
{
int n = GetInt();
int[] a = new int[n];
// 1 2 3 6 4 8 5 10
for(int i=0; i<n; i++)
{
if(i%2 == 0)
{
int v = i/2;
a[i] = 2*v+1;
} else
a[i] = 2*a[i-1];
}
// Console.WriteLine("Check : " + Check(a));
string ans = string.Join(" ",a);
Console.WriteLine(ans);
}
public static bool Check(int[] a)
{
for(int i=0; i<a.Length-1; i++)
{
if(a[i] > 2*a.Length)
return false;
if(i%2 == 0 && a[i+1]%a[i] != 0)
return false;
if(i%2 == 1 && a[i+1]%a[i] == 0)
return false;
}
return true;
}
}
package main
import (
"bufio"
"bytes"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
tc := readNum(reader)
var buf bytes.Buffer
for tc > 0 {
tc--
n := readNum(reader)
res := solve(n)
for i := 0; i < n; i++ {
buf.WriteString(fmt.Sprintf("%d ", res[i]))
}
buf.WriteByte('\n')
}
fmt.Print(buf.String())
}
func readUint64(bytes []byte, from int, val *uint64) int {
i := from
var tmp uint64
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp
return i
}
func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}
func readString(reader *bufio.Reader) string {
s, _ := reader.ReadString('\n')
for i := 0; i < len(s); i++ {
if s[i] == '\n' {
return s[:i]
}
}
return s
}
func readNum(reader *bufio.Reader) (a int) {
bs, _ := reader.ReadBytes('\n')
readInt(bs, 0, &a)
return
}
func readTwoNums(reader *bufio.Reader) (a int, b int) {
res := readNNums(reader, 2)
a, b = res[0], res[1]
return
}
func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
res := readNNums(reader, 3)
a, b, c = res[0], res[1], res[2]
return
}
func readNNums(reader *bufio.Reader, n int) []int {
res := make([]int, n)
x := 0
bs, _ := reader.ReadBytes('\n')
for i := 0; i < n; i++ {
for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
x++
}
x = readInt(bs, x, &res[i])
}
return res
}
func solve(n int) []int {
res := make([]int, n)
for i := 1; i <= n; i += 2 {
res[i-1] = 2*(i/2) + 1
}
for i := 2; i <= n; i += 2 {
res[i-1] = 2 * res[i-2]
}
return res
}
In our experience, we suggest you solve this Alternating Divisibility CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Alternating Divisibility CodeChef Solution.
I hope this Alternating Divisibility CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.
Keep Learning!