#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
using namespace std;
bool test(int dizi[]);
unsigned long getpow(int y);
unsigned long long result=0;
unsigned long getpow(int y) {
unsigned long tot=1;
for(;y>0;y--) {
tot*=10;
}
return tot;
}
void make(int* iarr)
{
if(iarr[0]==0) {
return;
}
if(iarr[3] % 2 != 0) return;
if(iarr[5] % 5 != 0) return;
unsigned long tot;
tot=iarr[9] + iarr[8]*10 + iarr[7]*100;
if(tot%17!=0) return;
tot=(tot/10) + iarr[6] * 100;
if(tot%13!=0) return;
tot=(tot/10) + iarr[5] * 100;
if(tot%11!=0) return;
tot=(tot/10) + iarr[4] * 100;
if(tot%7!=0) return;
tot=(tot/10) + iarr[3] * 100;
tot=(tot/10) + iarr[2] * 100;
if(tot%3!=0) return;
tot = 0;
for(int i=0; i<10; ++i) {
tot+=iarr[i]*getpow(9-i);
}
result+=tot;
}
int main()
{
clock_t tStart = clock();
int iarr[10] = {1,0,2,3,4,5,6,7,8,9};
sort(iarr,iarr+10);
make(iarr);
while(next_permutation(iarr,iarr+10))
make(iarr);
cout << "Project Euler - Problem 43(Sub-string divisibility)\n";
cout << "Result :" << result << " efekanpulatli.blogspot.com" << endl;
printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
system("pause");
return 0;
}

Hiç yorum yok:
Yorum Gönder