# Untitled

Sep 6th, 2020
1,441
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. //Pablo Soares Dias    31821BSI007
2. //Bruno Ferreira Silva  31521BSI005
3. #include <stdio.h>
4. #include <math.h>
5.
6. unsigned long long int  contar(long long int num){
7.
8.     if(num<10) return 1;
9.
10.     return contar(num/10)+1;
11.
12.     }
13.
14. unsigned long long int  high(long long int  num){
15.
16.     unsigned long long int  x=contar(num)/2;
17.
18.     x=num/pow(10,x);
19.
20.     return x;
21.
22.     }
23.
24. unsigned long long int low(long long int  num){
25.
26.     long long int x=contar(num)/2;
27.
28.     x=num%((long long int)(pow(10,x)));
29.
30.     return x;
31.     }
32.
33. unsigned long long int karatsuba(double  num1,double  num2){
34.
35.   if (num1 < 10||num2 < 10)
36.        return num1*num2;
37.
38.
39.   int m=fmax(contar(num1),contar(num2));
40.
41.   int m2 =ceil (m/2);
42.
43.   unsigned  long long int a = high(num1);
44.   unsigned  long long int b = low(num1);
45.   unsigned  long long int c = high(num2);
46.   unsigned  long long int d = low(num2);
47.
48.
49.   unsigned long long int  z0 = karatsuba(b,d);
50.   unsigned long long int  z2 = karatsuba(a,c);
51.   unsigned long long int  z1=karatsuba(a+b,c+d)-z2-z0;
52.
53.
54.   return (z2*pow(10,m2*2))+(z1*pow(10,m2))+(z0);
55.
56.   }
57.
58.
59. int main(){
60.
61.     long long int x,y;
62.
63.     printf("Digite um valor 1: ");
64.     scanf("%lli",&x);
65.
66.     printf("Digite um valor 2: ");
67.     scanf("%lli",&y);
68.
69.     printf("%lli\n",x*y);
70.     printf("%lli\n",karatsuba(x,y));
71.
72.
73.    return 0;
74. }
RAW Paste Data