Files
contests/projecteuler/078/main.cpp

49 lines
1.2 KiB
C++

#include <bits/stdc++.h>
using namespace std;
vector<long long> partition_function;
long long partitioning(long long n){
long long result = 0;
for(long long k = 1; k <= n; ++k){
long long lower = n - k*(3 * k - 1) / 2;
long long upper = n - k*(3 * k + 1) / 2;
result = (result + (k % 2 == 0 ? -1 : 1) * ((upper >= 0 ? partition_function[upper] : 0) + (lower >=0 ? partition_function[lower] : 0))) % 1000000;
}
if(result < 0){
result += 1000000;
}
return result;
}
int main(){
cout << "Hello this is Patrick" << endl;
auto start = chrono::high_resolution_clock::now();
// Basically the same partitioning function as in PE 76
partition_function.push_back(1);
long long n = 1;
long long result = 1;
while(result != 0){
result = partitioning(n);
// cout << n << " ";
// cout << result << " ";
partition_function.push_back(result);
n++;
}
cout << n - 1 << endl;
auto duration = chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start);
cout << (float)duration.count()/1000 << endl;
return 0;
}