Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Golbach Conjecture
- //Sem Loops (No Loops)
- #include<stdio.h>
- #define TAM 100000
- int primos[TAM], primo[TAM], TAMANHO = 0, LIMITE, pmaior, pmin, soma, numero;
- void preenche_vetor(int);
- void zerar_primos(int);
- void jota(int, int);
- void primo_f(int, int);
- void limite(int, int);
- void Goldbach(int, int, int);
- void listaGoldbach(int);
- void preenche_vetor(int x)
- {
- if(x != TAM)
- {
- primos[x] = x + 1;
- preenche_vetor(x + 1);
- }
- }
- void zerar_primos(int x)
- {
- int j;
- if(x != TAM)
- {
- if(primos[x] != 0)
- {
- j = x + primos[x];
- if(j*2 < TAM)
- {
- jota(j, x);
- }
- else
- return;
- }
- zerar_primos(x + 1);
- }
- }
- void jota(int j, int x)
- {
- if(j < TAM)
- {
- primos[j] = 0;
- jota(j + primos[x], x);
- }
- }
- void primo_f(int x, int y)
- {
- if(x != TAM)
- {
- if(primos[x] != 0)
- {
- primo[y] = primos[x];
- TAMANHO++;
- primo_f(x + 1, y + 1);
- }
- else
- primo_f(x + 1, y);
- }
- }
- void limite(int x, int y)
- {
- if(primo[y] <= x)
- limite(x, y + 1);
- else
- LIMITE = y;
- }
- void Goldbach(int num, int limit, int min)
- {
- pmaior = primo[limit];
- pmin = primo[min];
- soma = pmaior + pmin;
- if(soma < num)
- Goldbach(num, limit, min + 1);
- else if(soma > num)
- Goldbach(num, limit - 1, 0);
- }
- void listaGoldbach(int x)
- {
- if(x <= numero)
- {
- limite(x, 0);
- Goldbach(x, LIMITE - 1, 0);
- printf("%d = %d + %d\n", x, pmaior, pmin);
- listaGoldbach(x + 2);
- }
- }
- int main()
- {
- printf("Digite um número: ");
- scanf("%d", &numero);
- if(numero % 2 != 0)
- printf("\nO número deve ser par!\n");
- else
- {
- preenche_vetor(0);
- primos[0] = 0;
- zerar_primos(1);
- primo_f(0, 0);
- listaGoldbach(4);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment