Skip to content

Latest commit

 

History

History

Solutions

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Editorial

Save Money

  • Bruteforce approach
    • You can simply run a loop from 1 to n and add all ODD numbers. Then print the sum.
    • The time complexity will be O(n). But this will give you TLE.
  • Optimized Approach
    • If you observe you will notice a pattern.
    • The sum of first x ODD numbers is x2.
      • Example: 5 is the 3rd ODD number (Before that we have 1 and 3).So here x = 3.The sum of 1+3+5 = 9 which is equal to 32 or x2.
    • So you just have to identify which ODD number it is and square that to get the answer.
      • (7 is 4th ODD number so square of 4 will give me the sum of all ODD numbers from 1 to 7, 9 is 5th ODD number so square of 5 will give me the sum of all ODD numbers from 1 to 9)
  • Solution

Evenly Divisible

  • If we want to get a number which will be divisible by all the given N numbers then we just have to calculate the LCM (Least Common Multiple) (লসাগু) of those N numbers.

  • Solution