Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

unknow754389's blog

By unknow754389, history, 17 months ago, In English

I need the solution for this problem https://cses.fi/problemset/task/3423 thanks you !!

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
17 months ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

Ideia: For some number n search for the first i in [1, n] such that n + i is equal to a prime. If no answer exists then it's impossible (because n must be matched with someone). After that you can generate pairs

(n, i), (n-1, i+1), (n-2, i+2), ..., (i, n)

And you reduced the problem from n to i-1. The largest prime gape for numbers ≤ 1e5 is 34 (between 73,577 and 73,607), so basically all cases will reduce at most to the case where n ≤ 33. Then I did some small cases and simply guessforced that there would always be a solution and it passed. Hope this helps!