Блог пользователя njha1999

Автор njha1999, история, 7 лет назад, По-английски

Either this is something strangely deep or i have to revisit time complexity analysis for a piece of code !!

#include <iostream>
int main()
{
    long long int t=1e18,a=0; 

    while(t--) a++;
    std::cout<<a;
    return 0;
}

This code executes in 15 ms codeforces / codechef ide! How is that even possible?

May be this question is too dumb but any help is appreciated. Thanks!

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

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +35 Проголосовать: не нравится

Codeforces will compile it with -O2, which means the code will be optimized. This code is so simple that even the compiler will figure out that all this really long while loop does is sets a to $$$10^{18}$$$ and t to 0.