×

# ENIGMA08 - Editorial

Sword in the game

Author and Editorialist : Sunny Karira

Medium

# Pre-requisites

Dynamic Programming, Math

# Problem

To find the damage done by golden sword and the damage will be calculated as the number of numbers on the slice of [1,N].

# Quick Explanation

This problem can be solved using inclusion-exclusion principle.

# Explanation

If fa1a2..ak(n) is the answer, then the following formula works:  fa1a2..ak(n) = fa2a3..ak(n) - fa2..ak(floor(n/a1))

But if you write only this recursive function, you get TLE.

The quickest approach was to solve the question using DP and memorize the answers for small n and all ai.

# Solution:

This question is marked "community wiki".

464
accept rate: 10%

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,680
×2,595
×2,172
×877
×42

question asked: 16 Oct '15, 22:17

question was seen: 552 times

last updated: 16 Oct '15, 22:43