#include "stdafx.h"
#include <iostream>
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include <time.h>
using namespace std;
bool prime(int y);
bool prime(int y) {
if (y % 2 == 0)
return false;
for (int i = 3; i <= (int) sqrt((double) y); i++) {
if (y % i == 0)
return false;
}
return true;
}
void make() {
int dizi[100000],i,k=1,count=0,res=0,result;
dizi[0]=2;
unsigned long long tot=0;
for(i=3;i<1000000;i++) {
if(prime(i) == true) {
dizi[k] = i;
tot+=i;
k++;
}
}
for(int i=k;i>=0;i--) {
int m=0;
tot=dizi[i];
for(m=0;m<i;m++) {
count=1;
for(int c=i-1;c>=m;--c) {
if((tot+dizi[c]) > 1000000) {
break;
}else {
tot+=dizi[c];
count++;
if(prime(tot) == true) {
if(count>res) {
result=tot;
res=count;
}
}
}
}
}
}
cout << "Project Euler - Problem 50\n";
cout << "Result :" << result << " efekanpulatli.blogspot.com" << endl;
}
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