Блог пользователя comingsoon.cpp

Автор comingsoon.cpp, история, 3 месяца назад, По-английски

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
  • Проголосовать: не нравится

»
3 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

n-k ?)

  • »
    »
    3 месяца назад, # ^ |
    Rev. 2   Проголосовать: нравится +8 Проголосовать: не нравится

    Lolzzzz, I'm such a dumb a**.... My actual solution was (n — (k+1)) + 1

    Didn't realize it was that simple honestly.

»
3 месяца назад, # |
  Проголосовать: нравится +42 Проголосовать: не нравится

max(n — k, 0) ?

»
3 месяца назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

I think that is good for problem A of Div4.

»
3 месяца назад, # |
  Проголосовать: нравится +75 Проголосовать: не нравится

Answer = $$$\max(\frac{(n-k)^2}{n-k}, \lim_{x\rightarrow\infty}\frac{3x}{2x^2})$$$