fork download
  1. #include <bits/stdc++.h>
  2. #include "mpi.h"
  3. using namespace std;
  4.  
  5. void solve(long long n, long long &cnt) {
  6. cnt = 0;
  7. while (n > 2) {
  8. long long step = 5;
  9. long long current_sum = 2;
  10. while (n >= current_sum + step) {
  11. current_sum += step;
  12. step += 3;
  13. }
  14. n -= current_sum;
  15. cnt++;
  16. }
  17. if (n >= 2) {
  18. cnt++;
  19. }
  20. }
  21.  
  22. int main(int argc, char *argv[]) {
  23. MPI_Init(&argc, &argv);
  24. int rank, size;
  25. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  26. MPI_Comm_size(MPI_COMM_WORLD, &size);
  27.  
  28. int testcases;
  29. if (rank == 0) {
  30. cin >> testcases;
  31. }
  32. MPI_Bcast(&testcases, 1, MPI_INT, 0, MPI_COMM_WORLD);
  33.  
  34. int cases_per_process = testcases / size;
  35. int start_index = rank * cases_per_process;
  36. int end_index = (rank == size - 1) ? testcases : (rank + 1) * cases_per_process;
  37. vector<long long> results(end_index - start_index);
  38. for (int i = start_index; i < end_index; ++i) {
  39. long long n;
  40. cin >> n;
  41. solve(n, results[i - start_index]);
  42. }
  43.  
  44. vector<long long> all_results(testcases);
  45. MPI_Gather(results.data(), cases_per_process, MPI_LONG_LONG,
  46. all_results.data(), cases_per_process, MPI_LONG_LONG,
  47. 0, MPI_COMM_WORLD);
  48.  
  49. if (rank == 0) {
  50. for (int i = 0; i < testcases; ++i) {
  51. cout << all_results[i] << endl;
  52. }
  53. }
  54.  
  55. MPI_Finalize();
  56. return 0;
  57. }
Success #stdin #stdout #stderr 0.29s 40780KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "using namespace"
Execution halted