When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

vermapri's blog

By vermapri, history, 4 years ago, In English

We first make the array elements zero by choosing last index(n) and modding with 1.

Then add the prime number(P)>=n*2+1 by choosing the last index(n).Therefore all the elements of array will become prime number P.

Then Starting from initial index 0 to n-2 mod with a[i]-i which will bring us 0 ,1 ,2 ,3 ,4 to prime number(P).

We are choosing prime number >=n*2+1 because while modding with a[i]-i, a[i]-i should always be greater than all the numbers we have in the array before i index. Therefore for simplicity we've taken a number >=n*2+1.

Link for problem --------------------: https://codeforces.com/problemset/problem/1088/C

Solution

prime = []
def SieveOfEratosthenes():
    n = 6000
    global prime
    prime = [True for q in range(n + 1)]
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n + 1, p):
                prime[i] = False
        p += 1
SieveOfEratosthenes()
I = input
n=int(I())
a=list(map(int,I().split()))
p=0
i=n*2+1
while True:
    if prime[i]==True:
        p=i
        break
    i+=1
ans=['2 '+str(n)+' 1','1 '+str(n)+' '+str(p)]
for i in range(n-1):
    ans.append('2 '+str(i+1)+' '+str(p-i))
print(n+1)
for i in ans:
    print(i)
  • Vote: I like it
  • -7
  • Vote: I do not like it

| Write comment?