43 lines
700 B
C++
43 lines
700 B
C++
#include <iostream>
|
|
#include <thread>
|
|
#include <vector>
|
|
using namespace std;
|
|
|
|
int times(int x){
|
|
int r = 1;
|
|
for(int i = 2; i <= x; i++) r *= i;
|
|
return r;
|
|
}
|
|
|
|
void sum_to_n(int n, int& result){
|
|
int tmp = 0;
|
|
for(int i = 1; i <= n; i++) tmp += i;
|
|
result = tmp;
|
|
}
|
|
|
|
void fact_table(int n, vector<int>& out){
|
|
out.resize(n);
|
|
for(int i = 1; i <= n; i++){
|
|
out[i-1] = times(i);
|
|
}
|
|
}
|
|
|
|
int main(){
|
|
int n;
|
|
cin >> n;
|
|
|
|
int sum;
|
|
vector<int> facts;
|
|
int fn;
|
|
|
|
thread t1(sum_to_n, n, ref(sum));
|
|
thread t2(fact_table, n, ref(facts));
|
|
thread t3([&](){ fn = times(n); });
|
|
|
|
t1.join();
|
|
t2.join();
|
|
t3.join();
|
|
|
|
cout << sum << endl;
|
|
}
|