2 Nisan 2013 Salı

Fourty sixth solution of Project Euler - Goldbach's other conjecture




#include "stdafx.h"
#include <iostream>
#include<stdio.h>
#include <cmath>
#include "efe.h"
#include <time.h>
using namespace std;
bool prime(unsigned long long y);

bool prime(unsigned long long y) {
 for (unsigned long long i = 3; i <= (int) sqrt((double) y); i++) {
 if (y % i == 0)
 return false;
 }
 return true;
}

void make() {
int c,lim=0,dizi[10000];
dizi[0]=2;
for(int i=3;i<10000;i+=2){
if(prime(i)==1) {
dizi[lim] = i;
lim++;
}
}
int k=0;
double kare;

    for(int i=11;i<10000;i+=2) {
bool efe=0;
if(prime(i)!=1) {
k=0;
do {
c=i;
c-=dizi[k];
k++;
if(c%2==1) {
                continue;
}
c/=2;
kare = sqrt((double) c);
kare = ((int)kare);
if(c/kare==sqrt((long double) c)) {
           efe=1;
break;
}

}while(c>0);
if(efe==0) {
cout << "Project Euler - Problem 46(Goldbach's other conjecture)\n";
                cout << "Result :" <<i << " efekanpulatli.blogspot.com" << endl;
break;
}
}
}

}
int main() {
clock_t tStart = clock();
          make();
    printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
 system("pause");
return 0;
}

Hiç yorum yok:

Yorum Gönder