kali.ok's blog

By kali.ok, history, 8 years ago, In English

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 ?

  • Vote: I like it
  • -4
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
  Vote: I like it +12 Vote: I do not like it

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.