Блог пользователя kali.ok

Автор kali.ok, история, 8 лет назад, По-английски

in the last contest i have participate there a problem called "Johny Likes Numbers" " 678A - Johny Likes Numbers " as i found the shortest c++ solution was using one line


#include <cstdio> int main() { int n, k; scanf("%d %d",&n, &k); printf("%d\n",(n / k + 1) * k); }

how i can found this short formula to solve mathematical problems i've tried on several problems that had mathematical formula and found it's very hard to get it done can anyone advice me to get more powerful in problems like this ?

  • Проголосовать: нравится
  • -4
  • Проголосовать: не нравится

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

Formulas are derived, not memorized, and it certainly takes practice to develop the number sense necessary to create meaningful formulas to solve real problems.

Have you asked yourself exactly why (n/k + 1) * k works for the problem? If you cannot figure out why, take it as your first step to find out why and how it is correct.