Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

Commit 0410af27 authored by Guangting Yu's avatar Guangting Yu
Browse files

single thread

parent 682c00ed
#include <iostream>
#include <cassert>
#include <numeric>
#include <ranges>
#include <vector>
#include <cmath>
using namespace std;
template<class num>
num gcd(num a, num b){
return a==0 ? b : gcd(b%a, a);
template<class container>
auto gcd(container C){
auto ans = C.front();
for(auto& n : C){
ans = gcd(ans, n);
if(ans==1){return ans;}
return ans;
class EulerSum{
size_t length;
size_t power;
size_t range;
void thread_manager(){
// serial
for(auto s=range; s<2*range; ++s){
void thread_parent(){
// serial implementation
auto r=ranges::iota_view(range, 2*range);
for_each(r.begin(), r.end(), thread_child);
void thread_child(size_t sum){
vector<size_t> v(length,1);
void check_sum(const vector<size_t>& v){
double powersum=0.0;
powersum+=pow(n, power);
double sumroot = round(pow(powersum, 1.0/power));
if(abs(powersum-pow(sumroot, power))<1e-2){
print_solution(v, sumroot);
// solutions are sparse, no need for mutex
void print_solution(const vector<size_t>& v, double sum){
printf("%.0f^%lu\t=\t", sum, power);
printf("%lu^%lu", v.front(), power);
for(auto it=v.begin()+1; it!=v.end();it++){
printf("\t+\t%lu^%lu", *it, power);
// single thread, recursion
void generate_simplex(vector<size_t>& v, const size_t sum, size_t idx){
v.back()=sum-accumulate(v.begin(), v.begin()+idx, 0);
for(v[idx]=(idx==0 ? 1: v[idx-1]);
accumulate(v.begin(), v.begin()+idx+1, 0)<=sum-(idx+2==v.size() ? v[idx] : v.size()-idx);
generate_simplex(v, sum, idx+1);
EulerSum(auto l, auto p, auto r):
length(l), power(p), range(r) {
......@@ -20,7 +81,7 @@ public:
cerr << endl;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment