Different Subarray Sum Problem

2.7

44 votes
Number Theory, Modulus Arithmetic, Math, C++, Number theory
Problem

You are given positive integer n. Construct any array a1,a2,an, such that:

  • 0ai30000
  • For all pairs i,j such that 1ijn, the values of ai+ai+1++aj should be distinct.

Input format 

  • The single line  contains integer n - the length of the array.

Output format

  • Find any array such that all of the conditions are hold.

Constraints

  •     1n5103
Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

Subarray sums are: 1,2,4,8,16,3,7,15,31,6,14,30,12,28,24. . So you can see what, all the numbers are different.

Editor Image

?