fork(1) download
  1. #include <iostream>
  2. #include <math.h>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main(void) {
  9. int n, value, copy, sqrt_, i;
  10. int arr[1000], count;
  11. long long sum;
  12. cin >> n;
  13. while(n > 0) {
  14. vector <int> factors;
  15. cin >> value;
  16. copy = value;
  17. sum = 0;
  18. count = 0;
  19. if(copy == 1) {
  20. cout << 0 << endl;
  21. }
  22. else {
  23. arr[0] = 1;
  24. count++;
  25. while(copy%2 == 0) {
  26. arr[count] = 2;
  27. copy = copy/2;
  28. count++;
  29. }
  30. i = 3;
  31. sqrt_ = sqrt(value);
  32. while(copy > 1 && i <= sqrt_) {
  33. if(copy % i == 0) {
  34. arr[count] = i;
  35. count++;
  36. copy = copy/i;
  37. }
  38. else {
  39. i = i+2;
  40. }
  41. }
  42. if(copy > 1) {
  43. arr[count] = copy;
  44. count++;
  45. }
  46. for(i = 1; i <= count; i++) {//decide number of elements
  47. for(int j = 0; j <= (count-i); j++) {//decide starting elements
  48. int num = 1;
  49. for(int k = j;k < (j+i) ; k++) {//multiply and store elements
  50. num = num * arr[k];
  51. }
  52. if(num < value) {
  53. auto alpha = find(factors.begin(), factors.end(),num);
  54. if(alpha == factors.end()) {
  55. factors.push_back(num);
  56. }
  57. }
  58. }
  59. }
  60. int vecsize = factors.size();
  61. for(int l = 0; l < vecsize; l++) {
  62. sum = sum + factors[l];
  63. }
  64. cout << sum << endl;
  65. }
  66. n--;
  67. }
  68. return 0;
  69. }
  70.  
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
Standard output is empty