Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Alternate solution for problem-1088C (Ehab and a 2-operation task)

Правка en2, от vermapri, 2020-07-27 14:34:13

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(1) to n-1 mod with a[i]-i which will bring us 0 ,1 ,2 ,3 ,4 -------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 all the numbers we now have in the array. Therefore for simplicity we've taken a number >=n*2+1.

Link for problem --------------------: https://codeforces.me/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)`

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en6 Английский vermapri 2020-07-27 15:14:10 7 Tiny change: 'tial index(1) to n-1 mod with ' -> 'tial index 0 to n-2 mod with '
en5 Английский vermapri 2020-07-27 14:53:47 24
en4 Английский vermapri 2020-07-27 14:38:06 10 Tiny change: ' ,2 ,3 ,4 -------prime numb' -> ' ,2 ,3 ,4 to prime numb'
en3 Английский vermapri 2020-07-27 14:35:27 56
en2 Английский vermapri 2020-07-27 14:34:13 76
en1 Английский vermapri 2020-07-27 14:22:21 1338 Initial revision (published)