-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPPCM_PGCD
55 lines (49 loc) · 813 Bytes
/
PPCM_PGCD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//PLUS PETIT COMMUN MULTIPLE
__lcm(A, B);
int ppcm(int a,int b){
int p=a*b;
while (a!=b) if (a<b) b-=a; else a-=b;
return p/a;
}
int PPCM(int a, int b)
{
int ppcm = (a > b) ? a : b;
// Toujours vrai
while(1)
{
if( ppcm%a == 0 && ppcm%b == 0 )
{
printf("PPCM de %d et %d = %d", a, b, ppcm);
break;
}
++ppcm;
}
return 0;
}
//PLUS GRAND COMMUN DIVISEUR
__gcd(A, B);
---!methode recursive----
int PGCD(int a, int b)
{
if(a==b)
{
return a;
}
else
{
if(a>b)
return PGCD(a-b, b);
else
return PGCD(a, b-a);
}
}
int PGCD(int x, int y){
int a=x;
int b=y;
while (a!=b)
{
while (a>b) b=b+y;
while (a<b) a=a+x;
}
return a;
}