Farnan.PUST's blog

By Farnan.PUST, history, 7 years ago, In English

I can do it in O(N) time. but can it be more faster?

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

| Write comment?
»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Use inclusion/exclusion principle.

»
7 years ago, # |
  Vote: I like it +8 Vote: I do not like it

floor(N / 3) + floor(N / 5) — floor(N / 15)

»
7 years ago, # |
  Vote: I like it +5 Vote: I do not like it

As you said below N. So N cannot be accounted for. The formula will be

floor((N-1)/3) + floor((N-1)/5) — floor((N-1)/LCM(3,5))