vermapri's blog

By vermapri, history, 22 months 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

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

At each i you need to mod a[i] with (prime_no-i)....your explanation has got it wrong with a[i]-i.