Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static long karatsubaMethod(long x,long y)
- {
- long a, b, c, d,ac,bd;
- int len = (int) Math.Floor(Math.Log10(x)+1);
- len /= 2;
- if (len <= 1)
- return x * y;
- a = x / (long)Math.Floor(Math.Pow(10, len));
- b = x % (long)Math.Floor(Math.Pow(10, len));
- c = y / (long)Math.Floor(Math.Pow(10, len));
- d = y % (long)Math.Floor(Math.Pow(10, len));
- ac = karatsubaMethod(a, c);
- bd = karatsubaMethod(b, d);
- return ac * (long)Math.Floor(Math.Pow(10, 2*len))
- +(ac+bd-karatsubaMethod(a-b,c-d))*(long)Math.Floor(Math.Pow(10, len))
- + bd;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement