Commit 37a5f1f07dd34e205191c82d6946a751bf64ee2d
1 parent
b8af5d95
tpSD jusqu'a complexitee
Showing
34 changed files
with
1984 additions
and
1 deletions
Show diff stats
No preview for this file type
... | ... | @@ -0,0 +1,17 @@ |
1 | +.PHONY: clean,real-clean | |
2 | +LD = gcc | |
3 | +CC = gcc | |
4 | +CFLAGS = -Wall -W -Werror | |
5 | +SRC=$(wildcard *.c) | |
6 | +OBJ=$(SRC:.c=.o) | |
7 | +prog : $(OBJ) | |
8 | + $(LD) -o $@ $^ | |
9 | + | |
10 | +%.o : %.c | |
11 | + $(CC) $(CFLAGS) -c $^ | |
12 | + | |
13 | +clean : | |
14 | + rm -f *.o | |
15 | + | |
16 | +real-clean : clean | |
17 | + rm -f prog | |
0 | 18 | \ No newline at end of file | ... | ... |
No preview for this file type
... | ... | @@ -0,0 +1,42 @@ |
1 | +#include <stdio.h> | |
2 | +#include <ctype.h> | |
3 | +#include <stdlib.h> | |
4 | +#include "chaine.h" | |
5 | + | |
6 | +void init_chaine(struct chaine* A){ | |
7 | + | |
8 | + A->i=0; | |
9 | + A->n=4; | |
10 | + A->s=(char*)malloc(A->n*sizeof(char)); | |
11 | + | |
12 | +} | |
13 | + | |
14 | +void ajout_chaine(struct chaine* A,char c){ | |
15 | + | |
16 | + if(A->i==A->n){ | |
17 | + A->n=A->n+4; | |
18 | + A->s=realloc(A->s,A->n*sizeof(char)); | |
19 | + A->s[A->i]=c; | |
20 | + A->i=A->i+1; | |
21 | + | |
22 | + }else{ | |
23 | + A->s[A->i]=c; | |
24 | + A->i=A->i+1; | |
25 | + } | |
26 | +} | |
27 | + | |
28 | + | |
29 | +void imprime_chaine(struct chaine A){ | |
30 | + int j; | |
31 | + | |
32 | + for (j=0;j<=A.i;j++){ | |
33 | + printf("%c",A.s[j]); | |
34 | + } | |
35 | + printf("\n"); | |
36 | + | |
37 | + | |
38 | +} | |
39 | + | |
40 | +void clear_chaine(struct chaine* A){ | |
41 | + free(A->s); | |
42 | +} | ... | ... |
No preview for this file type
... | ... | @@ -0,0 +1,22 @@ |
1 | +#include <stdio.h> | |
2 | +#include <ctype.h> | |
3 | +#include <stdlib.h> | |
4 | +#include "chaine.h" | |
5 | + | |
6 | + | |
7 | + | |
8 | +int main(){ | |
9 | +int c; | |
10 | +struct chaine A; | |
11 | +init_chaine(&A); | |
12 | +c=getchar(); | |
13 | + | |
14 | +while(! isspace(c)){ | |
15 | + ajout_chaine(&A,c); | |
16 | + c=getchar(); | |
17 | +} | |
18 | + | |
19 | +imprime_chaine(A); | |
20 | +clear_chaine(&A); | |
21 | +return(0); | |
22 | +} | ... | ... |
No preview for this file type
No preview for this file type
No preview for this file type
... | ... | @@ -0,0 +1,17 @@ |
1 | +.PHONY: clean,real-clean | |
2 | +LD = gcc | |
3 | +CC = gcc | |
4 | +CFLAGS = -Wall -W -Werror | |
5 | +SRC=$(wildcard *.c) | |
6 | +OBJ=$(SRC:.c=.o) | |
7 | +prog : $(OBJ) | |
8 | + $(LD) -o $@ $^ | |
9 | + | |
10 | +%.o : %.c | |
11 | + $(CC) $(CFLAGS) -c $^ | |
12 | + | |
13 | +clean : | |
14 | + rm -f *.o | |
15 | + | |
16 | +real-clean : clean | |
17 | + rm -f prog | |
0 | 18 | \ No newline at end of file | ... | ... |
No preview for this file type
... | ... | @@ -0,0 +1,20 @@ |
1 | +#include "chaine.h" | |
2 | +#include <stdlib.h> | |
3 | +#include <stdio.h> | |
4 | + | |
5 | +void init_chaine(struct chaine* C) { | |
6 | + init_liste_char (&C->L); | |
7 | +} | |
8 | +void ajout_chaine(struct chaine* C,char c){ | |
9 | + ajouter_en_tete_liste_char (&C->L, c); | |
10 | +} | |
11 | +void ajoutQueue_chaine(struct chaine* C,char c){ | |
12 | + ajouter_en_queue_liste_char (&C->L, c); | |
13 | +} | |
14 | +void clear_chaine(struct chaine* C){ | |
15 | + clear_liste_char (&C->L); | |
16 | + | |
17 | +} | |
18 | +void imprime_chaine(struct chaine* C){ | |
19 | + imprimer_liste_char (&C->L); | |
20 | +} | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +#include "liste_char.h" | |
2 | + | |
3 | + | |
4 | +struct chaine{ | |
5 | + struct liste_char L; | |
6 | +}; | |
7 | + | |
8 | +extern void init_chaine(struct chaine*); | |
9 | +extern void ajout_chaine(struct chaine*,char); | |
10 | +extern void ajoutQueue_chaine(struct chaine*,char); | |
11 | +extern void clear_chaine(struct chaine*); | |
12 | +extern void imprime_chaine(struct chaine*); | ... | ... |
No preview for this file type
... | ... | @@ -0,0 +1,82 @@ |
1 | +#include "liste_char.h" | |
2 | +#include <stdlib.h> | |
3 | +#include <stdio.h> | |
4 | + | |
5 | +void init_liste_char (struct liste_char* L){ | |
6 | + L->tete = NIL; | |
7 | + L->nbchar = 0; | |
8 | +} | |
9 | + | |
10 | +void clear_liste_char (struct liste_char* L){ | |
11 | + struct maillon_char* tmp; | |
12 | + struct maillon_char* suivant; | |
13 | + | |
14 | + int i = 0; | |
15 | + tmp = L->tete; | |
16 | + for(i = 0; i < L->nbchar; i++){ | |
17 | + suivant = tmp->next; | |
18 | + free(tmp); | |
19 | + tmp = suivant; | |
20 | + } | |
21 | +} | |
22 | + | |
23 | +void imprimer_liste_char (struct liste_char* L){ | |
24 | + | |
25 | + if(L->tete == NIL){ | |
26 | + printf("EmptyList\n"); | |
27 | + | |
28 | + }else{ | |
29 | + struct maillon_char* M; | |
30 | + int i; | |
31 | + M = L->tete; | |
32 | + for(i = 0; i < (L->nbchar); i++){ | |
33 | + printf("%c",M->value); | |
34 | + M = M->next; | |
35 | + } | |
36 | + } | |
37 | + printf("\n"); | |
38 | +} | |
39 | + | |
40 | + | |
41 | +/* | |
42 | + * Ajout d'un char en entête de liste | |
43 | + */ | |
44 | +void ajouter_en_tete_liste_char (struct liste_char* L, char c){ | |
45 | + | |
46 | + struct maillon_char* nouveau; | |
47 | + | |
48 | + nouveau = (struct maillon_char*)malloc(sizeof(struct maillon_char)); | |
49 | + if(nouveau == NIL){ | |
50 | + fprintf(stderr,"error: NoMoreMemory"); | |
51 | + exit(1); | |
52 | + } | |
53 | + | |
54 | + nouveau->value= c; | |
55 | + nouveau->next=L->tete; | |
56 | + L->tete=nouveau; | |
57 | + L->nbchar +=1; | |
58 | + | |
59 | +} | |
60 | + | |
61 | +void ajouter_en_queue_liste_char (struct liste_char* L, char c){ | |
62 | + if(L->tete == NIL){ | |
63 | + ajouter_en_tete_liste_char (L, c); | |
64 | + } | |
65 | + struct maillon_char* nouveau; | |
66 | + | |
67 | + nouveau = (struct maillon_char*)malloc(sizeof(struct maillon_char)); | |
68 | + if(nouveau == NIL){ | |
69 | + fprintf(stderr,"error: NoMoreMemory"); | |
70 | + exit(1); | |
71 | + } | |
72 | + struct maillon_char* m; | |
73 | + m=L->tete; | |
74 | + while(m->next!=NIL){ | |
75 | + m=m->next; | |
76 | + } | |
77 | + nouveau->value=c; | |
78 | + nouveau->next=NIL; | |
79 | + m->next=nouveau; | |
80 | + L->nbchar +=1; | |
81 | + | |
82 | +} | ... | ... |
... | ... | @@ -0,0 +1,56 @@ |
1 | +#if ! defined (LISTE_CHAR_H) | |
2 | +#define LISTE_CHAR_H 1 | |
3 | + | |
4 | +struct maillon_char | |
5 | +{ char value; | |
6 | + struct maillon_char* next; | |
7 | +}; | |
8 | + | |
9 | +struct liste_char | |
10 | +{ struct maillon_char* tete; | |
11 | + int nbchar; | |
12 | +}; | |
13 | + | |
14 | +#define NIL (struct maillon_char*)0 | |
15 | + | |
16 | +/* | |
17 | + * Constructeur | |
18 | + * Initialise son paramètre à la liste vide | |
19 | + */ | |
20 | +extern void init_liste_char (struct liste_char*); | |
21 | + | |
22 | +/* | |
23 | + * Destructeur | |
24 | + */ | |
25 | +extern void clear_liste_char (struct liste_char*); | |
26 | + | |
27 | +/* | |
28 | + * Ajout d'un char en entête de liste | |
29 | + */ | |
30 | +extern void ajouter_en_tete_liste_char (struct liste_char*, char); | |
31 | + | |
32 | + | |
33 | +/* | |
34 | + * Ajout d'un char en queue de liste | |
35 | + */ | |
36 | +extern void ajouter_en_queue_liste_char (struct liste_char*, char); | |
37 | + | |
38 | + | |
39 | +/* | |
40 | + * Affecte à *d la valeur du premier élément de L et supprime cet élément de L. | |
41 | + * La liste L est supposée non vide. | |
42 | + */ | |
43 | +extern void extraire_tete_liste_char (char* d, struct liste_char* L); | |
44 | + | |
45 | +/* | |
46 | + * Impression. | |
47 | + */ | |
48 | +extern void imprimer_liste_char (struct liste_char*); | |
49 | + | |
50 | +/* | |
51 | + * Copie liste dst -> source | |
52 | + */ | |
53 | +extern void set_liste_char | |
54 | + (struct liste_char* dst, struct liste_char* src); | |
55 | + | |
56 | +#endif | ... | ... |
No preview for this file type
No preview for this file type
... | ... | @@ -0,0 +1,12 @@ |
1 | +CC=gcc | |
2 | +CFLAGS=-g -Wall -Wmissing-prototypes | |
3 | +LDFLAGS=-g | |
4 | +objects := $(patsubst %.c,%.o,$(wildcard *.c)) | |
5 | +all: main | |
6 | +clean: | |
7 | + -rm $(objects) | |
8 | + -rm main | |
9 | +main: $(objects) | |
10 | +# gcc -MM *.c pour obtenir les deux lignes ci-dessous | |
11 | +liste_double.o: liste_double.c liste_double.h | |
12 | +main.o: main.c liste_double.h | ... | ... |
... | ... | @@ -0,0 +1,105 @@ |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | +#include <assert.h> | |
4 | +#include "liste_double.h" | |
5 | + | |
6 | +void init_liste_double (struct liste_double* L) | |
7 | +{ | |
8 | + L->tete = (struct maillon_double*)0; | |
9 | + L->nbelem = 0; | |
10 | +} | |
11 | + | |
12 | +void ajouter_en_tete_liste_double (struct liste_double* L, double d) | |
13 | +{ struct maillon_double* nouveau; | |
14 | + | |
15 | + nouveau = (struct maillon_double*)malloc (sizeof (struct maillon_double)); | |
16 | + assert (nouveau != (struct maillon_double*)0); | |
17 | +/* appeler ici un éventuel constructeur pour nouveau->value */ | |
18 | + nouveau->value = d; /* affectation de la valeur */ | |
19 | + nouveau->next = L->tete; | |
20 | + L->tete = nouveau; | |
21 | + L->nbelem += 1; | |
22 | +} | |
23 | + | |
24 | +void clear_liste_double (struct liste_double* L) | |
25 | +{ struct maillon_double* courant; | |
26 | + struct maillon_double* suivant; | |
27 | + int i; | |
28 | + | |
29 | + courant = L->tete; | |
30 | + for (i = 0; i < L->nbelem; i++) | |
31 | + { suivant = courant->next; | |
32 | +/* appeler ici un éventuel destructeur pour nouveau->value */ | |
33 | + free (courant); | |
34 | + courant = suivant; | |
35 | + } | |
36 | +} | |
37 | + | |
38 | +/* | |
39 | + * Sous-fonction de set_liste_double. | |
40 | + * Si L = [m1, m2, ..., mn] avant l'appel alors | |
41 | + * L = [mn, ..., m2, m1] après l'appel. | |
42 | + * Aucune allocation dynamique n'est effectuée. | |
43 | + * Seuls les pointeurs sont modifiés | |
44 | + */ | |
45 | + | |
46 | +static void retourner_liste_double (struct liste_double* L) | |
47 | +{ struct maillon_double *precedent, *courant, *suivant; | |
48 | + int i; | |
49 | + | |
50 | + if (L->nbelem >= 2) | |
51 | + { courant = L->tete; | |
52 | + suivant = courant->next; | |
53 | + courant->next = (struct maillon_double*)0; | |
54 | + for (i = 1; i < L->nbelem; i++) | |
55 | + { precedent = courant; | |
56 | + courant = suivant; | |
57 | + suivant = suivant->next; | |
58 | + courant->next = precedent; | |
59 | + } | |
60 | + L->tete = courant; | |
61 | + } | |
62 | +} | |
63 | + | |
64 | +void set_liste_double (struct liste_double* dst, struct liste_double* src) | |
65 | +{ struct maillon_double* M; | |
66 | + int i; | |
67 | + | |
68 | + if (dst != src) | |
69 | + { clear_liste_double (dst); | |
70 | + init_liste_double (dst); | |
71 | + M = src->tete; | |
72 | + for (i = 0; i < src->nbelem; i++) | |
73 | + { ajouter_en_tete_liste_double (dst, M->value); | |
74 | + M = M->next; | |
75 | + } | |
76 | + retourner_liste_double (dst); | |
77 | + } | |
78 | +} | |
79 | + | |
80 | +void extraire_tete_liste_double (double* d, struct liste_double* L) | |
81 | +{ struct maillon_double* tete; | |
82 | + | |
83 | + assert (L->nbelem != 0); | |
84 | + tete = L->tete; | |
85 | + *d = tete->value; /* affectation */ | |
86 | + L->tete = tete->next; | |
87 | + L->nbelem -= 1; | |
88 | + free (tete); | |
89 | +} | |
90 | + | |
91 | +void imprimer_liste_double (struct liste_double* L) | |
92 | +{ struct maillon_double* M; | |
93 | + int i; | |
94 | + | |
95 | + printf ("["); | |
96 | + M = L->tete; | |
97 | + for (i = 0; i < L->nbelem; i++) | |
98 | + { if (i == 0) | |
99 | + printf ("%f", M->value); | |
100 | + else | |
101 | + printf (", %f", M->value); | |
102 | + M = M->next; | |
103 | + } | |
104 | + printf ("]\n"); | |
105 | +} | ... | ... |
... | ... | @@ -0,0 +1,72 @@ |
1 | +#if ! defined (LISTE_DOUBLE_H) | |
2 | +#define LISTE_DOUBLE_H 1 | |
3 | + | |
4 | +/********************************************************************** | |
5 | + * IMPLANTATION | |
6 | + * | |
7 | + * Spécification de l'implantation | |
8 | + * | |
9 | + * Implantation des listes simplement chaînées de doubles | |
10 | + * | |
11 | + * Les maillons sont alloués dynamiquement. | |
12 | + * Le champ next du dernier maillon vaut (struct maillon_double*)0 | |
13 | + * | |
14 | + * Le champ tete d'une liste pointe vers le premier maillon | |
15 | + * Le champ nbelem est égal au nombre de maillons de la liste | |
16 | + * La liste vide est codée par (tete, nbelem) = ((struct maillon_double*)0, 0) | |
17 | + * | |
18 | + * Des listes distinctes ont des maillons distincts (pas de maillon partagé). | |
19 | + **********************************************************************/ | |
20 | + | |
21 | +struct maillon_double | |
22 | +{ double value; | |
23 | + struct maillon_double* next; | |
24 | +}; | |
25 | + | |
26 | +struct liste_double | |
27 | +{ struct maillon_double* tete; | |
28 | + int nbelem; | |
29 | +}; | |
30 | + | |
31 | +/********************************************************************** | |
32 | + * PROTOTYPES DES FONCTIONS (TYPE ABSTRAIT) | |
33 | + **********************************************************************/ | |
34 | + | |
35 | +/* | |
36 | + * Constructeur. Initialise son paramètre à la liste vide | |
37 | + */ | |
38 | + | |
39 | +extern void init_liste_double (struct liste_double*); | |
40 | + | |
41 | +/* | |
42 | + * Destructeur | |
43 | + */ | |
44 | + | |
45 | +extern void clear_liste_double (struct liste_double*); | |
46 | + | |
47 | +/* | |
48 | + * Affecte une copie de src à dst | |
49 | + */ | |
50 | + | |
51 | +extern void set_liste_double | |
52 | + (struct liste_double* dst, struct liste_double* src); | |
53 | + | |
54 | +/* | |
55 | + * Ajout d'un double en tête de liste | |
56 | + */ | |
57 | + | |
58 | +extern void ajouter_en_tete_liste_double (struct liste_double*, double); | |
59 | + | |
60 | +/* | |
61 | + * Affecte à *d la valeur du premier élément de L et supprime cet élément de L. | |
62 | + * La liste L est supposée non vide. | |
63 | + */ | |
64 | + | |
65 | +extern void extraire_tete_liste_double (double* d, struct liste_double* L); | |
66 | + | |
67 | +/* | |
68 | + * Impression. | |
69 | + */ | |
70 | + | |
71 | +extern void imprimer_liste_double (struct liste_double*); | |
72 | +#endif | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +#include "liste_double.h" | |
2 | + | |
3 | +int main () | |
4 | +{ struct liste_double A; | |
5 | + | |
6 | + init_liste_double (&A); | |
7 | + | |
8 | + ajouter_en_tete_liste_double (&A, -0.1); | |
9 | + ajouter_en_tete_liste_double (&A, 0.0); | |
10 | + ajouter_en_tete_liste_double (&A, 3.14); | |
11 | + | |
12 | + imprimer_liste_double (&A); | |
13 | + | |
14 | + clear_liste_double (&A); | |
15 | + return 0; | |
16 | +} | ... | ... |
... | ... | @@ -0,0 +1,42 @@ |
1 | +#include <stdio.h> | |
2 | +#include <ctype.h> | |
3 | +#include <stdlib.h> | |
4 | +#include "chaine.h" | |
5 | +#include "liste_char.h" | |
6 | + | |
7 | + | |
8 | + | |
9 | + | |
10 | +int main(){ | |
11 | + | |
12 | + | |
13 | +char a ='a'; | |
14 | +char b ='b'; | |
15 | +struct chaine A; | |
16 | +init_chaine(&A); | |
17 | +imprime_chaine(&A); | |
18 | +ajout_chaine(&A,a); | |
19 | +ajoutQueue_chaine(&A,b); | |
20 | +ajoutQueue_chaine(&A,a); | |
21 | +imprime_chaine(&A); | |
22 | +clear_chaine(&A); | |
23 | +return(0); | |
24 | +} | |
25 | + | |
26 | + | |
27 | +/* | |
28 | +//Main de test liste_char | |
29 | +int main(){ | |
30 | +struct liste_char L; | |
31 | +init_liste_char(&L); | |
32 | +imprimer_liste_char(&L); | |
33 | + | |
34 | +ajouter_en_tete_liste_char(&L, 'c'); | |
35 | +ajouter_en_tete_liste_char(&L, 'b'); | |
36 | +ajouter_en_queue_liste_char(&L, 'b'); | |
37 | +ajouter_en_queue_liste_char(&L, 'a'); | |
38 | +imprimer_liste_char(&L); | |
39 | +clear_liste_char(&L); | |
40 | + | |
41 | +return(0); | |
42 | +}*/ | ... | ... |
No preview for this file type
No preview for this file type
Tp7_Struct/Tp7.c
... | ... | @@ -170,7 +170,7 @@ int main(int argc, char *argv[]){ |
170 | 170 | printf("Le nouveau numero de %s sera: %s\n",argv[2], argv[3]); |
171 | 171 | } else if ( argc == 3 && strcmp(argv[1],"supprimer")==0 ){ |
172 | 172 | deletePers(argv[2],&annuaire); |
173 | - } else if ( argc != 7 && strcmp(argv[1],"ajouter")==0 ){ | |
173 | + } else if ( argc ==8 && strcmp(argv[1],"ajouter")==0 ){ | |
174 | 174 | ///annuaire ajouter Dupont 01 01 2011 0328753542 |
175 | 175 | |
176 | 176 | Personne p; | ... | ... |
Tp7_Struct/Tp7.o
No preview for this file type
Tp7_Struct/prog
No preview for this file type
No preview for this file type
... | ... | @@ -0,0 +1,600 @@ |
1 | +# n f(n) | |
2 | + 1 2 | |
3 | + 2 11 | |
4 | + 3 33 | |
5 | + 4 46 | |
6 | + 5 94 | |
7 | + 6 120 | |
8 | + 7 150 | |
9 | + 8 167 | |
10 | + 9 267 | |
11 | + 10 319 | |
12 | + 11 375 | |
13 | + 12 405 | |
14 | + 13 469 | |
15 | + 14 503 | |
16 | + 15 541 | |
17 | + 16 562 | |
18 | + 17 766 | |
19 | + 18 870 | |
20 | + 19 978 | |
21 | + 20 1034 | |
22 | + 21 1150 | |
23 | + 22 1210 | |
24 | + 23 1274 | |
25 | + 24 1308 | |
26 | + 25 1440 | |
27 | + 26 1508 | |
28 | + 27 1580 | |
29 | + 28 1618 | |
30 | + 29 1698 | |
31 | + 30 1740 | |
32 | + 31 1786 | |
33 | + 32 1811 | |
34 | + 33 2223 | |
35 | + 34 2431 | |
36 | + 35 2643 | |
37 | + 36 2751 | |
38 | + 37 2971 | |
39 | + 38 3083 | |
40 | + 39 3199 | |
41 | + 40 3259 | |
42 | + 41 3495 | |
43 | + 42 3615 | |
44 | + 43 3739 | |
45 | + 44 3803 | |
46 | + 45 3935 | |
47 | + 46 4003 | |
48 | + 47 4075 | |
49 | + 48 4113 | |
50 | + 49 4381 | |
51 | + 50 4517 | |
52 | + 51 4657 | |
53 | + 52 4729 | |
54 | + 53 4877 | |
55 | + 54 4953 | |
56 | + 55 5033 | |
57 | + 56 5075 | |
58 | + 57 5239 | |
59 | + 58 5323 | |
60 | + 59 5411 | |
61 | + 60 5457 | |
62 | + 61 5553 | |
63 | + 62 5603 | |
64 | + 63 5657 | |
65 | + 64 5686 | |
66 | + 65 6514 | |
67 | + 66 6930 | |
68 | + 67 7350 | |
69 | + 68 7562 | |
70 | + 69 7990 | |
71 | + 70 8206 | |
72 | + 71 8426 | |
73 | + 72 8538 | |
74 | + 73 8982 | |
75 | + 74 9206 | |
76 | + 75 9434 | |
77 | + 76 9550 | |
78 | + 77 9786 | |
79 | + 78 9906 | |
80 | + 79 10030 | |
81 | + 80 10094 | |
82 | + 81 10570 | |
83 | + 82 10810 | |
84 | + 83 11054 | |
85 | + 84 11178 | |
86 | + 85 11430 | |
87 | + 86 11558 | |
88 | + 87 11690 | |
89 | + 88 11758 | |
90 | + 89 12026 | |
91 | + 90 12162 | |
92 | + 91 12302 | |
93 | + 92 12374 | |
94 | + 93 12522 | |
95 | + 94 12598 | |
96 | + 95 12678 | |
97 | + 96 12720 | |
98 | + 97 13260 | |
99 | + 98 13532 | |
100 | + 99 13808 | |
101 | + 100 13948 | |
102 | + 101 14232 | |
103 | + 102 14376 | |
104 | + 103 14524 | |
105 | + 104 14600 | |
106 | + 105 14900 | |
107 | + 106 15052 | |
108 | + 107 15208 | |
109 | + 108 15288 | |
110 | + 109 15452 | |
111 | + 110 15536 | |
112 | + 111 15624 | |
113 | + 112 15670 | |
114 | + 113 16002 | |
115 | + 114 16170 | |
116 | + 115 16342 | |
117 | + 116 16430 | |
118 | + 117 16610 | |
119 | + 118 16702 | |
120 | + 119 16798 | |
121 | + 120 16848 | |
122 | + 121 17044 | |
123 | + 122 17144 | |
124 | + 123 17248 | |
125 | + 124 17302 | |
126 | + 125 17414 | |
127 | + 126 17472 | |
128 | + 127 17534 | |
129 | + 128 17567 | |
130 | + 129 19227 | |
131 | + 130 20059 | |
132 | + 131 20895 | |
133 | + 132 21315 | |
134 | + 133 22159 | |
135 | + 134 22583 | |
136 | + 135 23011 | |
137 | + 136 23227 | |
138 | + 137 24087 | |
139 | + 138 24519 | |
140 | + 139 24955 | |
141 | + 140 25175 | |
142 | + 141 25619 | |
143 | + 142 25843 | |
144 | + 143 26071 | |
145 | + 144 26187 | |
146 | + 145 27079 | |
147 | + 146 27527 | |
148 | + 147 27979 | |
149 | + 148 28207 | |
150 | + 149 28667 | |
151 | + 150 28899 | |
152 | + 151 29135 | |
153 | + 152 29255 | |
154 | + 153 29731 | |
155 | + 154 29971 | |
156 | + 155 30215 | |
157 | + 156 30339 | |
158 | + 157 30591 | |
159 | + 158 30719 | |
160 | + 159 30851 | |
161 | + 160 30919 | |
162 | + 161 31875 | |
163 | + 162 32355 | |
164 | + 163 32839 | |
165 | + 164 33083 | |
166 | + 165 33575 | |
167 | + 166 33823 | |
168 | + 167 34075 | |
169 | + 168 34203 | |
170 | + 169 34711 | |
171 | + 170 34967 | |
172 | + 171 35227 | |
173 | + 172 35359 | |
174 | + 173 35627 | |
175 | + 174 35763 | |
176 | + 175 35903 | |
177 | + 176 35975 | |
178 | + 177 36515 | |
179 | + 178 36787 | |
180 | + 179 37063 | |
181 | + 180 37203 | |
182 | + 181 37487 | |
183 | + 182 37631 | |
184 | + 183 37779 | |
185 | + 184 37855 | |
186 | + 185 38155 | |
187 | + 186 38307 | |
188 | + 187 38463 | |
189 | + 188 38543 | |
190 | + 189 38707 | |
191 | + 190 38791 | |
192 | + 191 38879 | |
193 | + 192 38925 | |
194 | + 193 40009 | |
195 | + 194 40553 | |
196 | + 195 41101 | |
197 | + 196 41377 | |
198 | + 197 41933 | |
199 | + 198 42213 | |
200 | + 199 42497 | |
201 | + 200 42641 | |
202 | + 201 43213 | |
203 | + 202 43501 | |
204 | + 203 43793 | |
205 | + 204 43941 | |
206 | + 205 44241 | |
207 | + 206 44393 | |
208 | + 207 44549 | |
209 | + 208 44629 | |
210 | + 209 45233 | |
211 | + 210 45537 | |
212 | + 211 45845 | |
213 | + 212 46001 | |
214 | + 213 46317 | |
215 | + 214 46477 | |
216 | + 215 46641 | |
217 | + 216 46725 | |
218 | + 217 47057 | |
219 | + 218 47225 | |
220 | + 219 47397 | |
221 | + 220 47485 | |
222 | + 221 47665 | |
223 | + 222 47757 | |
224 | + 223 47853 | |
225 | + 224 47903 | |
226 | + 225 48571 | |
227 | + 226 48907 | |
228 | + 227 49247 | |
229 | + 228 49419 | |
230 | + 229 49767 | |
231 | + 230 49943 | |
232 | + 231 50123 | |
233 | + 232 50215 | |
234 | + 233 50579 | |
235 | + 234 50763 | |
236 | + 235 50951 | |
237 | + 236 51047 | |
238 | + 237 51243 | |
239 | + 238 51343 | |
240 | + 239 51447 | |
241 | + 240 51501 | |
242 | + 241 51897 | |
243 | + 242 52097 | |
244 | + 243 52301 | |
245 | + 244 52405 | |
246 | + 245 52617 | |
247 | + 246 52725 | |
248 | + 247 52837 | |
249 | + 248 52895 | |
250 | + 249 53123 | |
251 | + 250 53239 | |
252 | + 251 53359 | |
253 | + 252 53421 | |
254 | + 253 53549 | |
255 | + 254 53615 | |
256 | + 255 53685 | |
257 | + 256 53722 | |
258 | + 257 57046 | |
259 | + 258 58710 | |
260 | + 259 60378 | |
261 | + 260 61214 | |
262 | + 261 62890 | |
263 | + 262 63730 | |
264 | + 263 64574 | |
265 | + 264 64998 | |
266 | + 265 66690 | |
267 | + 266 67538 | |
268 | + 267 68390 | |
269 | + 268 68818 | |
270 | + 269 69678 | |
271 | + 270 70110 | |
272 | + 271 70546 | |
273 | + 272 70766 | |
274 | + 273 72490 | |
275 | + 274 73354 | |
276 | + 275 74222 | |
277 | + 276 74658 | |
278 | + 277 75534 | |
279 | + 278 75974 | |
280 | + 279 76418 | |
281 | + 280 76642 | |
282 | + 281 77534 | |
283 | + 282 77982 | |
284 | + 283 78434 | |
285 | + 284 78662 | |
286 | + 285 79122 | |
287 | + 286 79354 | |
288 | + 287 79590 | |
289 | + 288 79710 | |
290 | + 289 81498 | |
291 | + 290 82394 | |
292 | + 291 83294 | |
293 | + 292 83746 | |
294 | + 293 84654 | |
295 | + 294 85110 | |
296 | + 295 85570 | |
297 | + 296 85802 | |
298 | + 297 86726 | |
299 | + 298 87190 | |
300 | + 299 87658 | |
301 | + 300 87894 | |
302 | + 301 88370 | |
303 | + 302 88610 | |
304 | + 303 88854 | |
305 | + 304 88978 | |
306 | + 305 89934 | |
307 | + 306 90414 | |
308 | + 307 90898 | |
309 | + 308 91142 | |
310 | + 309 91634 | |
311 | + 310 91882 | |
312 | + 311 92134 | |
313 | + 312 92262 | |
314 | + 313 92770 | |
315 | + 314 93026 | |
316 | + 315 93286 | |
317 | + 316 93418 | |
318 | + 317 93686 | |
319 | + 318 93822 | |
320 | + 319 93962 | |
321 | + 320 94034 | |
322 | + 321 95950 | |
323 | + 322 96910 | |
324 | + 323 97874 | |
325 | + 324 98358 | |
326 | + 325 99330 | |
327 | + 326 99818 | |
328 | + 327 100310 | |
329 | + 328 100558 | |
330 | + 329 101546 | |
331 | + 330 102042 | |
332 | + 331 102542 | |
333 | + 332 102794 | |
334 | + 333 103302 | |
335 | + 334 103558 | |
336 | + 335 103818 | |
337 | + 336 103950 | |
338 | + 337 104970 | |
339 | + 338 105482 | |
340 | + 339 105998 | |
341 | + 340 106258 | |
342 | + 341 106782 | |
343 | + 342 107046 | |
344 | + 343 107314 | |
345 | + 344 107450 | |
346 | + 345 107990 | |
347 | + 346 108262 | |
348 | + 347 108538 | |
349 | + 348 108678 | |
350 | + 349 108962 | |
351 | + 350 109106 | |
352 | + 351 109254 | |
353 | + 352 109330 | |
354 | + 353 110414 | |
355 | + 354 110958 | |
356 | + 355 111506 | |
357 | + 356 111782 | |
358 | + 357 112338 | |
359 | + 358 112618 | |
360 | + 359 112902 | |
361 | + 360 113046 | |
362 | + 361 113618 | |
363 | + 362 113906 | |
364 | + 363 114198 | |
365 | + 364 114346 | |
366 | + 365 114646 | |
367 | + 366 114798 | |
368 | + 367 114954 | |
369 | + 368 115034 | |
370 | + 369 115638 | |
371 | + 370 115942 | |
372 | + 371 116250 | |
373 | + 372 116406 | |
374 | + 373 116722 | |
375 | + 374 116882 | |
376 | + 375 117046 | |
377 | + 376 117130 | |
378 | + 377 117462 | |
379 | + 378 117630 | |
380 | + 379 117802 | |
381 | + 380 117890 | |
382 | + 381 118070 | |
383 | + 382 118162 | |
384 | + 383 118258 | |
385 | + 384 118308 | |
386 | + 385 120480 | |
387 | + 386 121568 | |
388 | + 387 122660 | |
389 | + 388 123208 | |
390 | + 389 124308 | |
391 | + 390 124860 | |
392 | + 391 125416 | |
393 | + 392 125696 | |
394 | + 393 126812 | |
395 | + 394 127372 | |
396 | + 395 127936 | |
397 | + 396 128220 | |
398 | + 397 128792 | |
399 | + 398 129080 | |
400 | + 399 129372 | |
401 | + 400 129520 | |
402 | + 401 130668 | |
403 | + 402 131244 | |
404 | + 403 131824 | |
405 | + 404 132116 | |
406 | + 405 132704 | |
407 | + 406 133000 | |
408 | + 407 133300 | |
409 | + 408 133452 | |
410 | + 409 134056 | |
411 | + 410 134360 | |
412 | + 411 134668 | |
413 | + 412 134824 | |
414 | + 413 135140 | |
415 | + 414 135300 | |
416 | + 415 135464 | |
417 | + 416 135548 | |
418 | + 417 136760 | |
419 | + 418 137368 | |
420 | + 419 137980 | |
421 | + 420 138288 | |
422 | + 421 138908 | |
423 | + 422 139220 | |
424 | + 423 139536 | |
425 | + 424 139696 | |
426 | + 425 140332 | |
427 | + 426 140652 | |
428 | + 427 140976 | |
429 | + 428 141140 | |
430 | + 429 141472 | |
431 | + 430 141640 | |
432 | + 431 141812 | |
433 | + 432 141900 | |
434 | + 433 142568 | |
435 | + 434 142904 | |
436 | + 435 143244 | |
437 | + 436 143416 | |
438 | + 437 143764 | |
439 | + 438 143940 | |
440 | + 439 144120 | |
441 | + 440 144212 | |
442 | + 441 144576 | |
443 | + 442 144760 | |
444 | + 443 144948 | |
445 | + 444 145044 | |
446 | + 445 145240 | |
447 | + 446 145340 | |
448 | + 447 145444 | |
449 | + 448 145498 | |
450 | + 449 146838 | |
451 | + 450 147510 | |
452 | + 451 148186 | |
453 | + 452 148526 | |
454 | + 453 149210 | |
455 | + 454 149554 | |
456 | + 455 149902 | |
457 | + 456 150078 | |
458 | + 457 150778 | |
459 | + 458 151130 | |
460 | + 459 151486 | |
461 | + 460 151666 | |
462 | + 461 152030 | |
463 | + 462 152214 | |
464 | + 463 152402 | |
465 | + 464 152498 | |
466 | + 465 153230 | |
467 | + 466 153598 | |
468 | + 467 153970 | |
469 | + 468 154158 | |
470 | + 469 154538 | |
471 | + 470 154730 | |
472 | + 471 154926 | |
473 | + 472 155026 | |
474 | + 473 155422 | |
475 | + 474 155622 | |
476 | + 475 155826 | |
477 | + 476 155930 | |
478 | + 477 156142 | |
479 | + 478 156250 | |
480 | + 479 156362 | |
481 | + 480 156420 | |
482 | + 481 157216 | |
483 | + 482 157616 | |
484 | + 483 158020 | |
485 | + 484 158224 | |
486 | + 485 158636 | |
487 | + 486 158844 | |
488 | + 487 159056 | |
489 | + 488 159164 | |
490 | + 489 159592 | |
491 | + 490 159808 | |
492 | + 491 160028 | |
493 | + 492 160140 | |
494 | + 493 160368 | |
495 | + 494 160484 | |
496 | + 495 160604 | |
497 | + 496 160666 | |
498 | + 497 161126 | |
499 | + 498 161358 | |
500 | + 499 161594 | |
501 | + 500 161714 | |
502 | + 501 161958 | |
503 | + 502 162082 | |
504 | + 503 162210 | |
505 | + 504 162276 | |
506 | + 505 162536 | |
507 | + 506 162668 | |
508 | + 507 162804 | |
509 | + 508 162874 | |
510 | + 509 163018 | |
511 | + 510 163092 | |
512 | + 511 163170 | |
513 | + 512 163211 | |
514 | + 513 169863 | |
515 | + 514 173191 | |
516 | + 515 176523 | |
517 | + 516 178191 | |
518 | + 517 181531 | |
519 | + 518 183203 | |
520 | + 519 184879 | |
521 | + 520 185719 | |
522 | + 521 189075 | |
523 | + 522 190755 | |
524 | + 523 192439 | |
525 | + 524 193283 | |
526 | + 525 194975 | |
527 | + 526 195823 | |
528 | + 527 196675 | |
529 | + 528 197103 | |
530 | + 529 200491 | |
531 | + 530 202187 | |
532 | + 531 203887 | |
533 | + 532 204739 | |
534 | + 533 206447 | |
535 | + 534 207303 | |
536 | + 535 208163 | |
537 | + 536 208595 | |
538 | + 537 210319 | |
539 | + 538 211183 | |
540 | + 539 212051 | |
541 | + 540 212487 | |
542 | + 541 213363 | |
543 | + 542 213803 | |
544 | + 543 214247 | |
545 | + 544 214471 | |
546 | + 545 217923 | |
547 | + 546 219651 | |
548 | + 547 221383 | |
549 | + 548 222251 | |
550 | + 549 223991 | |
551 | + 550 224863 | |
552 | + 551 225739 | |
553 | + 552 226179 | |
554 | + 553 227935 | |
555 | + 554 228815 | |
556 | + 555 229699 | |
557 | + 556 230143 | |
558 | + 557 231035 | |
559 | + 558 231483 | |
560 | + 559 231935 | |
561 | + 560 232163 | |
562 | + 561 233951 | |
563 | + 562 234847 | |
564 | + 563 235747 | |
565 | + 564 236199 | |
566 | + 565 237107 | |
567 | + 566 237563 | |
568 | + 567 238023 | |
569 | + 568 238255 | |
570 | + 569 239179 | |
571 | + 570 239643 | |
572 | + 571 240111 | |
573 | + 572 240347 | |
574 | + 573 240823 | |
575 | + 574 241063 | |
576 | + 575 241307 | |
577 | + 576 241431 | |
578 | + 577 245011 | |
579 | + 578 246803 | |
580 | + 579 248599 | |
581 | + 580 249499 | |
582 | + 581 251303 | |
583 | + 582 252207 | |
584 | + 583 253115 | |
585 | + 584 253571 | |
586 | + 585 255391 | |
587 | + 586 256303 | |
588 | + 587 257219 | |
589 | + 588 257679 | |
590 | + 589 258603 | |
591 | + 590 259067 | |
592 | + 591 259535 | |
593 | + 592 259771 | |
594 | + 593 261623 | |
595 | + 594 262551 | |
596 | + 595 263483 | |
597 | + 596 263951 | |
598 | + 597 264891 | |
599 | + 598 265363 | |
600 | + 599 265839 | ... | ... |
... | ... | @@ -0,0 +1,258 @@ |
1 | +#include <stdlib.h> | |
2 | +#include <stdio.h> | |
3 | +#include <stdbool.h> | |
4 | +#include <math.h> | |
5 | +#include <assert.h> | |
6 | + | |
7 | +/* | |
8 | + * Représentation élémentaire d'un polynôme. | |
9 | + * On pourrait, au minimum, rajouter le degré ! | |
10 | + */ | |
11 | + | |
12 | +struct poly | |
13 | +{ double* T; /* le tableau des coefficients */ | |
14 | + bool dynamic; /* indique si T a été alloué dynamiquement */ | |
15 | + int n; /* la taille du tableau */ | |
16 | +}; | |
17 | + | |
18 | +/* | |
19 | + * Constructeur. Le tableau T est alloué dynamiquement | |
20 | + */ | |
21 | +void init_poly (struct poly* A, int n) | |
22 | +{ | |
23 | + A->T = (double*)malloc (n * sizeof (double)); | |
24 | + assert (A->T != (double*)0); | |
25 | + A->n = n; | |
26 | + A->dynamic = true; | |
27 | +} | |
28 | + | |
29 | +/* | |
30 | + * Autre constructeur. Le tableau T est passé en paramètre. | |
31 | + * Il n'est donc pas alloué dynamiquement | |
32 | + */ | |
33 | +void init2_poly (struct poly* A, double* T, int n) | |
34 | +{ | |
35 | + A->T = T; | |
36 | + A->n = n; | |
37 | + A->dynamic = false; | |
38 | +} | |
39 | + | |
40 | +/* | |
41 | + * Destructeur. | |
42 | + */ | |
43 | +void clear_poly (struct poly* A) | |
44 | +{ | |
45 | + if (A->dynamic) | |
46 | + free (A->T); | |
47 | +} | |
48 | + | |
49 | +/* | |
50 | + * L'impression d'un polynôme est plus technique qu'on ne le croit :-) | |
51 | + * On suppose que les doubles sont en fait des entiers | |
52 | + */ | |
53 | +void print_poly (struct poly* A) | |
54 | +{ long c; | |
55 | + int i; | |
56 | + bool b; | |
57 | + | |
58 | + b = false; | |
59 | + for (i = A->n - 1; i >= 0; i--) | |
60 | + { if (A->T[i] != 0.0) | |
61 | + { if (A->T[i] > 0) | |
62 | + { if (b) printf (" + "); | |
63 | + } else | |
64 | + { if (b) printf (" - "); else printf ("-"); | |
65 | + } | |
66 | + b = true; | |
67 | + if (A->T[i] > 0) c = (long)A->T[i]; else c = (long) - A->T[i]; | |
68 | + if (i == 0) | |
69 | + printf ("%ld", c); | |
70 | + else if (i == 1) | |
71 | + { if (c != 1) printf ("%ld*x", c); else printf ("x"); | |
72 | + } else | |
73 | + { if (c != 1) printf ("%ld*x^%d", c, i); else printf ("x^%d", i); | |
74 | + } | |
75 | + } | |
76 | + } | |
77 | + printf ("\n"); | |
78 | +} | |
79 | + | |
80 | +/* | |
81 | + * R = A + B | |
82 | + */ | |
83 | +int add_poly (struct poly* R, struct poly* A, struct poly* B) | |
84 | +{ | |
85 | + int nbOpe=0; | |
86 | + int i; | |
87 | + i = 0; | |
88 | + while (i < A->n && i < B->n) | |
89 | + { R->T[i] = A->T[i] + B->T[i]; | |
90 | + i += 1; | |
91 | + nbOpe+=1; | |
92 | + } | |
93 | + while (i < A->n) | |
94 | + { R->T[i] = A->T[i]; | |
95 | + i += 1; | |
96 | + } | |
97 | + while (i < B->n) | |
98 | + { R->T[i] = B->T[i]; | |
99 | + i += 1; | |
100 | + } | |
101 | + while (i < R->n) | |
102 | + { R->T[i] = 0.0; | |
103 | + i += 1; | |
104 | + } | |
105 | + return nbOpe; | |
106 | +} | |
107 | + | |
108 | +/* | |
109 | + * R = A - B | |
110 | + */ | |
111 | +int sub_poly (struct poly* R, struct poly* A, struct poly* B) | |
112 | +{ | |
113 | + int nbOpe=0; | |
114 | + int i; | |
115 | + i = 0; | |
116 | + while (i < A->n && i < B->n) | |
117 | + { R->T[i] = A->T[i] - B->T[i]; | |
118 | + i += 1; | |
119 | + nbOpe+=1; | |
120 | + } | |
121 | + while (i < A->n) | |
122 | + { R->T[i] = A->T[i]; | |
123 | + i += 1; | |
124 | + } | |
125 | + while (i < B->n) | |
126 | + { R->T[i] = - B->T[i]; | |
127 | + i += 1; | |
128 | + } | |
129 | + while (i < R->n) | |
130 | + { R->T[i] = 0.0; | |
131 | + i += 1; | |
132 | + } | |
133 | + return nbOpe; | |
134 | +} | |
135 | + | |
136 | +/* | |
137 | + * R = A * B par la méthode élémentaire | |
138 | + */ | |
139 | +int mul_poly (struct poly* R, struct poly* A, struct poly* B) | |
140 | +{ | |
141 | + int nbOpe=0; | |
142 | + int a, b; | |
143 | + for (a = 0; a < R->n; a++) | |
144 | + R->T[a] = 0.0; | |
145 | + for (a = 0; a < A->n; a++){ | |
146 | + for (b = 0; b < B->n; b++){ | |
147 | + R->T[a+b] = R->T[a+b] + A->T[a] * B->T[b]; | |
148 | + nbOpe+=2; | |
149 | + } | |
150 | + } | |
151 | + return nbOpe; | |
152 | +} | |
153 | + | |
154 | +/* | |
155 | + * R = A * B par la méthode de Karatsuba | |
156 | + */ | |
157 | +int Karatsuba (struct poly* R, struct poly* A, struct poly* B) | |
158 | +{ struct poly R0, R1, R2, A0, A1, B0, B1, tmpA, tmpB; | |
159 | + int i, p, q; | |
160 | + int nbOpe =0; | |
161 | + | |
162 | +/* | |
163 | + * L'algorithme élémentaire est utilisé pour les cas de base | |
164 | + */ | |
165 | + if (A->n == 1 || B->n == 1) | |
166 | + nbOpe+=mul_poly (R, A, B); | |
167 | + else | |
168 | + { | |
169 | + if (A->n < B->n) | |
170 | + p = A->n/2; | |
171 | + else | |
172 | + p = B->n/2; | |
173 | +/* | |
174 | + * Découper les polynômes A et B en deux se fait en temps constant | |
175 | + */ | |
176 | + init2_poly (&A0, A->T, p); | |
177 | + init2_poly (&A1, A->T + p, A->n - p); | |
178 | + init2_poly (&B0, B->T, p); | |
179 | + init2_poly (&B1, B->T + p, B->n - p); | |
180 | +/* | |
181 | + * Les polynômes R0 et R2 sont des sous-tableaux de R. | |
182 | + * On évite ainsi deux recopies de tableaux. | |
183 | + */ | |
184 | + init2_poly (&R0, R->T, 2*p-1); | |
185 | + init2_poly (&R2, R->T + 2*p, A->n + B->n - 1 - 2*p); | |
186 | + nbOpe+=Karatsuba (&R0, &A0, &B0); | |
187 | + nbOpe+=Karatsuba (&R2, &A1, &B1); | |
188 | +/* | |
189 | + * À ce stade, R = R0 + x^(2*p)*R2. On calcule maintenant R1. | |
190 | + */ | |
191 | + if (A0.n > A1.n) q = A0.n; else q = A1.n; | |
192 | + init_poly (&tmpA, q); | |
193 | + nbOpe+= add_poly (&tmpA, &A0, &A1); | |
194 | + if (B0.n > B1.n) q = B0.n; else q = B1.n; | |
195 | + init_poly (&tmpB, q); | |
196 | + nbOpe+=add_poly (&tmpB, &B0, &B1); | |
197 | + q = tmpA.n + tmpB.n - 1; | |
198 | + if (q < R0.n) q = R0.n; | |
199 | + if (q < R2.n) q = R2.n; | |
200 | + init_poly (&R1, q); | |
201 | + nbOpe+= Karatsuba (&R1, &tmpA, &tmpB); | |
202 | + nbOpe+= sub_poly (&R1, &R1, &R0); | |
203 | + nbOpe+= sub_poly (&R1, &R1, &R2); | |
204 | +/* | |
205 | + * R = R + x^p*R1 | |
206 | + */ | |
207 | + R->T[2*p-1] = 0; | |
208 | + for (i = 0; i < R1.n; i++){ | |
209 | + R->T[p+i] = R->T[p+i] + R1.T[i]; | |
210 | + nbOpe++; | |
211 | + } | |
212 | + | |
213 | + clear_poly (&A0); | |
214 | + clear_poly (&A1); | |
215 | + clear_poly (&B0); | |
216 | + clear_poly (&B1); | |
217 | + clear_poly (&R0); | |
218 | + clear_poly (&R1); | |
219 | + clear_poly (&R2); | |
220 | + clear_poly (&tmpA); | |
221 | + clear_poly (&tmpB); | |
222 | + } | |
223 | + return nbOpe; | |
224 | +} | |
225 | + | |
226 | +int main () | |
227 | +{ struct poly A, B, R; | |
228 | + int i, n, N; | |
229 | + int nbOpe =0; | |
230 | + int nbNumPoly=0; | |
231 | + srand48 ((long)421); | |
232 | + | |
233 | + N = 600; /* taille des polynômes */ | |
234 | + init_poly (&A, N); | |
235 | + init_poly (&B, N); | |
236 | + init_poly (&R, 2*N-1); | |
237 | + for (i = 0; i < N; i++) | |
238 | + { | |
239 | + A.T [i] = floor (10.0 * drand48 () - 5.0); | |
240 | + B.T [i] = floor (10.0 * drand48 () - 5.0); | |
241 | + } | |
242 | + printf("#\tn\tf(n)\n"); | |
243 | + for (n = 1; n < N; n++) | |
244 | + { | |
245 | + nbOpe=0; | |
246 | + nbNumPoly=0; | |
247 | + A.n = n; | |
248 | + B.n = n; | |
249 | + nbNumPoly=mul_poly (&R, &A, &B); | |
250 | + //print_poly (&R); | |
251 | + nbOpe=Karatsuba (&R, &A, &B); | |
252 | + //print_poly (&R); | |
253 | + // printf("\t%d\t%d",n, nbNumPoly); | |
254 | + printf("\t%d\t%d\n",n, nbOpe); | |
255 | + | |
256 | + } | |
257 | + | |
258 | +} | ... | ... |
... | ... | @@ -0,0 +1,600 @@ |
1 | +# n f(n) | |
2 | + 1 2 | |
3 | + 2 11 | |
4 | + 3 33 | |
5 | + 4 46 | |
6 | + 5 94 | |
7 | + 6 120 | |
8 | + 7 150 | |
9 | + 8 167 | |
10 | + 9 267 | |
11 | + 10 319 | |
12 | + 11 375 | |
13 | + 12 405 | |
14 | + 13 469 | |
15 | + 14 503 | |
16 | + 15 541 | |
17 | + 16 562 | |
18 | + 17 766 | |
19 | + 18 870 | |
20 | + 19 978 | |
21 | + 20 1034 | |
22 | + 21 1150 | |
23 | + 22 1210 | |
24 | + 23 1274 | |
25 | + 24 1308 | |
26 | + 25 1440 | |
27 | + 26 1508 | |
28 | + 27 1580 | |
29 | + 28 1618 | |
30 | + 29 1698 | |
31 | + 30 1740 | |
32 | + 31 1786 | |
33 | + 32 1811 | |
34 | + 33 2223 | |
35 | + 34 2431 | |
36 | + 35 2643 | |
37 | + 36 2751 | |
38 | + 37 2971 | |
39 | + 38 3083 | |
40 | + 39 3199 | |
41 | + 40 3259 | |
42 | + 41 3495 | |
43 | + 42 3615 | |
44 | + 43 3739 | |
45 | + 44 3803 | |
46 | + 45 3935 | |
47 | + 46 4003 | |
48 | + 47 4075 | |
49 | + 48 4113 | |
50 | + 49 4381 | |
51 | + 50 4517 | |
52 | + 51 4657 | |
53 | + 52 4729 | |
54 | + 53 4877 | |
55 | + 54 4953 | |
56 | + 55 5033 | |
57 | + 56 5075 | |
58 | + 57 5239 | |
59 | + 58 5323 | |
60 | + 59 5411 | |
61 | + 60 5457 | |
62 | + 61 5553 | |
63 | + 62 5603 | |
64 | + 63 5657 | |
65 | + 64 5686 | |
66 | + 65 6514 | |
67 | + 66 6930 | |
68 | + 67 7350 | |
69 | + 68 7562 | |
70 | + 69 7990 | |
71 | + 70 8206 | |
72 | + 71 8426 | |
73 | + 72 8538 | |
74 | + 73 8982 | |
75 | + 74 9206 | |
76 | + 75 9434 | |
77 | + 76 9550 | |
78 | + 77 9786 | |
79 | + 78 9906 | |
80 | + 79 10030 | |
81 | + 80 10094 | |
82 | + 81 10570 | |
83 | + 82 10810 | |
84 | + 83 11054 | |
85 | + 84 11178 | |
86 | + 85 11430 | |
87 | + 86 11558 | |
88 | + 87 11690 | |
89 | + 88 11758 | |
90 | + 89 12026 | |
91 | + 90 12162 | |
92 | + 91 12302 | |
93 | + 92 12374 | |
94 | + 93 12522 | |
95 | + 94 12598 | |
96 | + 95 12678 | |
97 | + 96 12720 | |
98 | + 97 13260 | |
99 | + 98 13532 | |
100 | + 99 13808 | |
101 | + 100 13948 | |
102 | + 101 14232 | |
103 | + 102 14376 | |
104 | + 103 14524 | |
105 | + 104 14600 | |
106 | + 105 14900 | |
107 | + 106 15052 | |
108 | + 107 15208 | |
109 | + 108 15288 | |
110 | + 109 15452 | |
111 | + 110 15536 | |
112 | + 111 15624 | |
113 | + 112 15670 | |
114 | + 113 16002 | |
115 | + 114 16170 | |
116 | + 115 16342 | |
117 | + 116 16430 | |
118 | + 117 16610 | |
119 | + 118 16702 | |
120 | + 119 16798 | |
121 | + 120 16848 | |
122 | + 121 17044 | |
123 | + 122 17144 | |
124 | + 123 17248 | |
125 | + 124 17302 | |
126 | + 125 17414 | |
127 | + 126 17472 | |
128 | + 127 17534 | |
129 | + 128 17567 | |
130 | + 129 19227 | |
131 | + 130 20059 | |
132 | + 131 20895 | |
133 | + 132 21315 | |
134 | + 133 22159 | |
135 | + 134 22583 | |
136 | + 135 23011 | |
137 | + 136 23227 | |
138 | + 137 24087 | |
139 | + 138 24519 | |
140 | + 139 24955 | |
141 | + 140 25175 | |
142 | + 141 25619 | |
143 | + 142 25843 | |
144 | + 143 26071 | |
145 | + 144 26187 | |
146 | + 145 27079 | |
147 | + 146 27527 | |
148 | + 147 27979 | |
149 | + 148 28207 | |
150 | + 149 28667 | |
151 | + 150 28899 | |
152 | + 151 29135 | |
153 | + 152 29255 | |
154 | + 153 29731 | |
155 | + 154 29971 | |
156 | + 155 30215 | |
157 | + 156 30339 | |
158 | + 157 30591 | |
159 | + 158 30719 | |
160 | + 159 30851 | |
161 | + 160 30919 | |
162 | + 161 31875 | |
163 | + 162 32355 | |
164 | + 163 32839 | |
165 | + 164 33083 | |
166 | + 165 33575 | |
167 | + 166 33823 | |
168 | + 167 34075 | |
169 | + 168 34203 | |
170 | + 169 34711 | |
171 | + 170 34967 | |
172 | + 171 35227 | |
173 | + 172 35359 | |
174 | + 173 35627 | |
175 | + 174 35763 | |
176 | + 175 35903 | |
177 | + 176 35975 | |
178 | + 177 36515 | |
179 | + 178 36787 | |
180 | + 179 37063 | |
181 | + 180 37203 | |
182 | + 181 37487 | |
183 | + 182 37631 | |
184 | + 183 37779 | |
185 | + 184 37855 | |
186 | + 185 38155 | |
187 | + 186 38307 | |
188 | + 187 38463 | |
189 | + 188 38543 | |
190 | + 189 38707 | |
191 | + 190 38791 | |
192 | + 191 38879 | |
193 | + 192 38925 | |
194 | + 193 40009 | |
195 | + 194 40553 | |
196 | + 195 41101 | |
197 | + 196 41377 | |
198 | + 197 41933 | |
199 | + 198 42213 | |
200 | + 199 42497 | |
201 | + 200 42641 | |
202 | + 201 43213 | |
203 | + 202 43501 | |
204 | + 203 43793 | |
205 | + 204 43941 | |
206 | + 205 44241 | |
207 | + 206 44393 | |
208 | + 207 44549 | |
209 | + 208 44629 | |
210 | + 209 45233 | |
211 | + 210 45537 | |
212 | + 211 45845 | |
213 | + 212 46001 | |
214 | + 213 46317 | |
215 | + 214 46477 | |
216 | + 215 46641 | |
217 | + 216 46725 | |
218 | + 217 47057 | |
219 | + 218 47225 | |
220 | + 219 47397 | |
221 | + 220 47485 | |
222 | + 221 47665 | |
223 | + 222 47757 | |
224 | + 223 47853 | |
225 | + 224 47903 | |
226 | + 225 48571 | |
227 | + 226 48907 | |
228 | + 227 49247 | |
229 | + 228 49419 | |
230 | + 229 49767 | |
231 | + 230 49943 | |
232 | + 231 50123 | |
233 | + 232 50215 | |
234 | + 233 50579 | |
235 | + 234 50763 | |
236 | + 235 50951 | |
237 | + 236 51047 | |
238 | + 237 51243 | |
239 | + 238 51343 | |
240 | + 239 51447 | |
241 | + 240 51501 | |
242 | + 241 51897 | |
243 | + 242 52097 | |
244 | + 243 52301 | |
245 | + 244 52405 | |
246 | + 245 52617 | |
247 | + 246 52725 | |
248 | + 247 52837 | |
249 | + 248 52895 | |
250 | + 249 53123 | |
251 | + 250 53239 | |
252 | + 251 53359 | |
253 | + 252 53421 | |
254 | + 253 53549 | |
255 | + 254 53615 | |
256 | + 255 53685 | |
257 | + 256 53722 | |
258 | + 257 57046 | |
259 | + 258 58710 | |
260 | + 259 60378 | |
261 | + 260 61214 | |
262 | + 261 62890 | |
263 | + 262 63730 | |
264 | + 263 64574 | |
265 | + 264 64998 | |
266 | + 265 66690 | |
267 | + 266 67538 | |
268 | + 267 68390 | |
269 | + 268 68818 | |
270 | + 269 69678 | |
271 | + 270 70110 | |
272 | + 271 70546 | |
273 | + 272 70766 | |
274 | + 273 72490 | |
275 | + 274 73354 | |
276 | + 275 74222 | |
277 | + 276 74658 | |
278 | + 277 75534 | |
279 | + 278 75974 | |
280 | + 279 76418 | |
281 | + 280 76642 | |
282 | + 281 77534 | |
283 | + 282 77982 | |
284 | + 283 78434 | |
285 | + 284 78662 | |
286 | + 285 79122 | |
287 | + 286 79354 | |
288 | + 287 79590 | |
289 | + 288 79710 | |
290 | + 289 81498 | |
291 | + 290 82394 | |
292 | + 291 83294 | |
293 | + 292 83746 | |
294 | + 293 84654 | |
295 | + 294 85110 | |
296 | + 295 85570 | |
297 | + 296 85802 | |
298 | + 297 86726 | |
299 | + 298 87190 | |
300 | + 299 87658 | |
301 | + 300 87894 | |
302 | + 301 88370 | |
303 | + 302 88610 | |
304 | + 303 88854 | |
305 | + 304 88978 | |
306 | + 305 89934 | |
307 | + 306 90414 | |
308 | + 307 90898 | |
309 | + 308 91142 | |
310 | + 309 91634 | |
311 | + 310 91882 | |
312 | + 311 92134 | |
313 | + 312 92262 | |
314 | + 313 92770 | |
315 | + 314 93026 | |
316 | + 315 93286 | |
317 | + 316 93418 | |
318 | + 317 93686 | |
319 | + 318 93822 | |
320 | + 319 93962 | |
321 | + 320 94034 | |
322 | + 321 95950 | |
323 | + 322 96910 | |
324 | + 323 97874 | |
325 | + 324 98358 | |
326 | + 325 99330 | |
327 | + 326 99818 | |
328 | + 327 100310 | |
329 | + 328 100558 | |
330 | + 329 101546 | |
331 | + 330 102042 | |
332 | + 331 102542 | |
333 | + 332 102794 | |
334 | + 333 103302 | |
335 | + 334 103558 | |
336 | + 335 103818 | |
337 | + 336 103950 | |
338 | + 337 104970 | |
339 | + 338 105482 | |
340 | + 339 105998 | |
341 | + 340 106258 | |
342 | + 341 106782 | |
343 | + 342 107046 | |
344 | + 343 107314 | |
345 | + 344 107450 | |
346 | + 345 107990 | |
347 | + 346 108262 | |
348 | + 347 108538 | |
349 | + 348 108678 | |
350 | + 349 108962 | |
351 | + 350 109106 | |
352 | + 351 109254 | |
353 | + 352 109330 | |
354 | + 353 110414 | |
355 | + 354 110958 | |
356 | + 355 111506 | |
357 | + 356 111782 | |
358 | + 357 112338 | |
359 | + 358 112618 | |
360 | + 359 112902 | |
361 | + 360 113046 | |
362 | + 361 113618 | |
363 | + 362 113906 | |
364 | + 363 114198 | |
365 | + 364 114346 | |
366 | + 365 114646 | |
367 | + 366 114798 | |
368 | + 367 114954 | |
369 | + 368 115034 | |
370 | + 369 115638 | |
371 | + 370 115942 | |
372 | + 371 116250 | |
373 | + 372 116406 | |
374 | + 373 116722 | |
375 | + 374 116882 | |
376 | + 375 117046 | |
377 | + 376 117130 | |
378 | + 377 117462 | |
379 | + 378 117630 | |
380 | + 379 117802 | |
381 | + 380 117890 | |
382 | + 381 118070 | |
383 | + 382 118162 | |
384 | + 383 118258 | |
385 | + 384 118308 | |
386 | + 385 120480 | |
387 | + 386 121568 | |
388 | + 387 122660 | |
389 | + 388 123208 | |
390 | + 389 124308 | |
391 | + 390 124860 | |
392 | + 391 125416 | |
393 | + 392 125696 | |
394 | + 393 126812 | |
395 | + 394 127372 | |
396 | + 395 127936 | |
397 | + 396 128220 | |
398 | + 397 128792 | |
399 | + 398 129080 | |
400 | + 399 129372 | |
401 | + 400 129520 | |
402 | + 401 130668 | |
403 | + 402 131244 | |
404 | + 403 131824 | |
405 | + 404 132116 | |
406 | + 405 132704 | |
407 | + 406 133000 | |
408 | + 407 133300 | |
409 | + 408 133452 | |
410 | + 409 134056 | |
411 | + 410 134360 | |
412 | + 411 134668 | |
413 | + 412 134824 | |
414 | + 413 135140 | |
415 | + 414 135300 | |
416 | + 415 135464 | |
417 | + 416 135548 | |
418 | + 417 136760 | |
419 | + 418 137368 | |
420 | + 419 137980 | |
421 | + 420 138288 | |
422 | + 421 138908 | |
423 | + 422 139220 | |
424 | + 423 139536 | |
425 | + 424 139696 | |
426 | + 425 140332 | |
427 | + 426 140652 | |
428 | + 427 140976 | |
429 | + 428 141140 | |
430 | + 429 141472 | |
431 | + 430 141640 | |
432 | + 431 141812 | |
433 | + 432 141900 | |
434 | + 433 142568 | |
435 | + 434 142904 | |
436 | + 435 143244 | |
437 | + 436 143416 | |
438 | + 437 143764 | |
439 | + 438 143940 | |
440 | + 439 144120 | |
441 | + 440 144212 | |
442 | + 441 144576 | |
443 | + 442 144760 | |
444 | + 443 144948 | |
445 | + 444 145044 | |
446 | + 445 145240 | |
447 | + 446 145340 | |
448 | + 447 145444 | |
449 | + 448 145498 | |
450 | + 449 146838 | |
451 | + 450 147510 | |
452 | + 451 148186 | |
453 | + 452 148526 | |
454 | + 453 149210 | |
455 | + 454 149554 | |
456 | + 455 149902 | |
457 | + 456 150078 | |
458 | + 457 150778 | |
459 | + 458 151130 | |
460 | + 459 151486 | |
461 | + 460 151666 | |
462 | + 461 152030 | |
463 | + 462 152214 | |
464 | + 463 152402 | |
465 | + 464 152498 | |
466 | + 465 153230 | |
467 | + 466 153598 | |
468 | + 467 153970 | |
469 | + 468 154158 | |
470 | + 469 154538 | |
471 | + 470 154730 | |
472 | + 471 154926 | |
473 | + 472 155026 | |
474 | + 473 155422 | |
475 | + 474 155622 | |
476 | + 475 155826 | |
477 | + 476 155930 | |
478 | + 477 156142 | |
479 | + 478 156250 | |
480 | + 479 156362 | |
481 | + 480 156420 | |
482 | + 481 157216 | |
483 | + 482 157616 | |
484 | + 483 158020 | |
485 | + 484 158224 | |
486 | + 485 158636 | |
487 | + 486 158844 | |
488 | + 487 159056 | |
489 | + 488 159164 | |
490 | + 489 159592 | |
491 | + 490 159808 | |
492 | + 491 160028 | |
493 | + 492 160140 | |
494 | + 493 160368 | |
495 | + 494 160484 | |
496 | + 495 160604 | |
497 | + 496 160666 | |
498 | + 497 161126 | |
499 | + 498 161358 | |
500 | + 499 161594 | |
501 | + 500 161714 | |
502 | + 501 161958 | |
503 | + 502 162082 | |
504 | + 503 162210 | |
505 | + 504 162276 | |
506 | + 505 162536 | |
507 | + 506 162668 | |
508 | + 507 162804 | |
509 | + 508 162874 | |
510 | + 509 163018 | |
511 | + 510 163092 | |
512 | + 511 163170 | |
513 | + 512 163211 | |
514 | + 513 169863 | |
515 | + 514 173191 | |
516 | + 515 176523 | |
517 | + 516 178191 | |
518 | + 517 181531 | |
519 | + 518 183203 | |
520 | + 519 184879 | |
521 | + 520 185719 | |
522 | + 521 189075 | |
523 | + 522 190755 | |
524 | + 523 192439 | |
525 | + 524 193283 | |
526 | + 525 194975 | |
527 | + 526 195823 | |
528 | + 527 196675 | |
529 | + 528 197103 | |
530 | + 529 200491 | |
531 | + 530 202187 | |
532 | + 531 203887 | |
533 | + 532 204739 | |
534 | + 533 206447 | |
535 | + 534 207303 | |
536 | + 535 208163 | |
537 | + 536 208595 | |
538 | + 537 210319 | |
539 | + 538 211183 | |
540 | + 539 212051 | |
541 | + 540 212487 | |
542 | + 541 213363 | |
543 | + 542 213803 | |
544 | + 543 214247 | |
545 | + 544 214471 | |
546 | + 545 217923 | |
547 | + 546 219651 | |
548 | + 547 221383 | |
549 | + 548 222251 | |
550 | + 549 223991 | |
551 | + 550 224863 | |
552 | + 551 225739 | |
553 | + 552 226179 | |
554 | + 553 227935 | |
555 | + 554 228815 | |
556 | + 555 229699 | |
557 | + 556 230143 | |
558 | + 557 231035 | |
559 | + 558 231483 | |
560 | + 559 231935 | |
561 | + 560 232163 | |
562 | + 561 233951 | |
563 | + 562 234847 | |
564 | + 563 235747 | |
565 | + 564 236199 | |
566 | + 565 237107 | |
567 | + 566 237563 | |
568 | + 567 238023 | |
569 | + 568 238255 | |
570 | + 569 239179 | |
571 | + 570 239643 | |
572 | + 571 240111 | |
573 | + 572 240347 | |
574 | + 573 240823 | |
575 | + 574 241063 | |
576 | + 575 241307 | |
577 | + 576 241431 | |
578 | + 577 245011 | |
579 | + 578 246803 | |
580 | + 579 248599 | |
581 | + 580 249499 | |
582 | + 581 251303 | |
583 | + 582 252207 | |
584 | + 583 253115 | |
585 | + 584 253571 | |
586 | + 585 255391 | |
587 | + 586 256303 | |
588 | + 587 257219 | |
589 | + 588 257679 | |
590 | + 589 258603 | |
591 | + 590 259067 | |
592 | + 591 259535 | |
593 | + 592 259771 | |
594 | + 593 261623 | |
595 | + 594 262551 | |
596 | + 595 263483 | |
597 | + 596 263951 | |
598 | + 597 264891 | |
599 | + 598 265363 | |
600 | + 599 265839 | ... | ... |
No preview for this file type