#include<cstdio> #define MAX 1010 int crivo[MAX + 1]; int primos[MAX + 1]; int n_primos = 0; using namespace std; void init_crivo() { for (int i = 2; i <= MAX; i++) if(!crivo[i]) { primos[n_primos++] = i; for (int j = i; i * j <= MAX; j++) crivo[i * j] = 1; } } bool es_primo(int n) { if(n == 1) return false; int i = 0; while(primos[i] * primos[i] <= n) { if(n % primos[i] == 0) return false; i++; } return true; } int main() { init_crivo(); int n, a, b; while(scanf("%d", &n)) { if(n == 0) break; bool find = false; a = 2, b = n - 2; while(a < n && b > 0 && !find) { if(es_primo(a) && es_primo(b)) printf("%d = %d + %d\n", n, a, b), find = true; a++, b--; } if(!find) printf("Goldbach's conjecture is wrong.\n"); } return 0; }
miércoles, 19 de octubre de 2011
Goldbach's Conjecture - TJU
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario