Yesterday my coach give me a hard problem "a + b".
In standard input gives two numbers a and b.
I must output sum a + b.
Please help me with this hard problem
UPD: YEE, I KNOW HOW TO SOLVE!
import time
a, b = map(int, input().split())
start = time.time()
time.sleep(a)
time.sleep(b)
print(time.time() - start)
go play fortnite u fortnite kid
you should just
print a + b
But if u solvin' extreme a+b with really big a and b, and few memory, the only way is to write long arythmetics on C++. Maybe long arythmetics in Java will work too (they are already in Java).
I can Solve "extreme a + b", but I can solve simple "a + b". Maybe I so stupid but that is true.
if $$$a+b\le10^8$$$:
otherwise I dont know
Quite good and effective algorithm!!!. But I've heard some student from china invented algorithm that solves it with complexity $$$ O(1) $$$. Is it true???
Actually, that loop works in O(1) if you used a compiler optimization flag like: O3
O3 unrolls the loop and if it detects repetition, it effectively optimizes it. So this works until $$$1e18$$$ if you used for example O3 compiler flag optimization! :D
Lol, i really didn't know about it (seriously). Thanks!
You're welcome! But how does the compiler its self calculates it in O(1)? Hmm? We should ask the person who made the compiler.
I've heard it's not $$$ O(1) $$$ really. It's $$$ O(log n ^ 2) $$$, but as there is usually no more, than 64 bytes, computers calculate it really fast. ($$$ n $$$ is length of number in binary).
(Maybe i'm wrong)
I thought it's actually not $$$O(n^{2})$$$ (and yep it should be without log, cause n is already log), but $$$O(n^{\log_3 2})$$$ if you use Karatsuba algorithm. And I heard about some algos, that work like $$$O(n \cdot \log n \cdot \log \log n)$$$ and $$$O(n \log n \cdot 2^{\log *n})$$$.
ZZZGen Yep, i know, but i'm 'bout how processor it makes). pavook in previous comments have said, that processors can do simple arithmetics in one cycle.
This joke is too old
A simple 3D segment tree does the job :D
I can't solve it. Please help.
std::cout << ( ( 2 * a + 2 * b ) — ( a + b ) ) + ( __gcd( (int)1e7 , 1 ) — pow( 2 , 0 ) ) ;
xD
Auto comment: topic has been updated by plagues (previous revision, new revision, compare).
Hmmm, your solution works really long and will get TLE if $$$0 \le a, b \le 10^5$$$
Life Limit exceeded :D
No, if a == b and b == 0 it work so fast
What are the min and max values for a and b? Let's see if we can write just some if-statements
$$$ 0 \le a, b \le 10^{18} $$$ maybe
А шо все такие англичане?
Lol I don't understand you)
Выйди, розбiйник
I understand only English and Берляндский languages
ору, togda viidi
drugoe delo!!! srazу ponяtno sтalo!!! Chё kak нe rodnoй??
hey guys, i found super simple solution with complexity $$$O(\log ab)$$$
But it's actually $$$O(\log (a + 1)(b + 1))$$$. ^-^
Hey, guys. I found a faster solution!