### comingsoon.cpp's blog

By comingsoon.cpp, history, 13 days ago,

I was trying to solve an exercise while studying basic probabilities and while solving the exercise, I thought of this problem which I thought was fun, so I decided to share it with my fellow noobs :)

Please if you're anything above a newbie, (in Ercole Visconti's voice) This problem is not for you (no offence) :)

Problem Statement

You have n tiles numbered from 1 through to n. You are also given an integer K. The task it to count all pairs of integers (a,b) from the n tiles whose difference is K. that means (a — b) = K

Input The one and only line of the input contains two positive integer n and K. Output Print the number of such pairs (a, b) whose difference is K, thank you.

Sample input 100 11 Sample output 89

• +24

 » 13 days ago, # |   0 n-k ?)
•  » » 13 days ago, # ^ | ← Rev. 2 →   +8 Lolzzzz, I'm such a dumb a**.... My actual solution was (n — (k+1)) + 1Didn't realize it was that simple honestly.
 » 13 days ago, # |   +42 max(n — k, 0) ?
 » 13 days ago, # |   +12 I think that is good for problem A of Div4.
 » 13 days ago, # |   +75 Answer = $\max(\frac{(n-k)^2}{n-k}, \lim_{x\rightarrow\infty}\frac{3x}{2x^2})$
•  » » 13 days ago, # ^ |   +20 Sadly, your solution will receive a runtime error when n=k :)
•  » » » 13 days ago, # ^ | ← Rev. 2 →   +95 Easy, to avoid division by zero, just add another limit: $\max(\lim_{x\rightarrow k}\frac{(n-x)^2}{n-x}, \lim_{x\rightarrow\infty}\frac{3x}{2x^2})$
•  » » » » 12 days ago, # ^ | ← Rev. 2 →   -38 .
•  » » » » » 12 days ago, # ^ |   +2 Spoiler