fork download
  1. #include <bits/stdc++.h>
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. string ltrim(const string &);
  7. string rtrim(const string &);
  8. vector<string> split(const string &);
  9.  
  10. /*
  11.  * Complete the 'getTotalX' function below.
  12.  *
  13.  * The function is expected to return an INTEGER.
  14.  * The function accepts following parameters:
  15.  * 1. INTEGER_ARRAY a
  16.  * 2. INTEGER_ARRAY b
  17.  */
  18.  
  19. int getTotalX(vector<int> a, vector<int> b) {
  20. int ucln = gcd(b[0],b[1]);
  21. for(int i=2; i<=b.size(); i++){
  22. ucln = gcd(ucln,b[i]);
  23. }
  24. int res =0;
  25. int bcnn = lcm(a[0],a[1]);
  26. for(int i=2; i<=a.size(); i++){
  27. if(bcnn<= ucln){
  28. for(int j=0; j<b.size(); j++){
  29. if(b[j] % bcnn != 0) continue;
  30. };
  31. else res++;
  32. }
  33. bcnn = lcm(bcnn,a[i]);
  34. }
  35. return res;
  36. }
  37.  
  38. int main()
  39. {
  40. ofstream fout(getenv("OUTPUT_PATH"));
  41.  
  42. string first_multiple_input_temp;
  43. getline(cin, first_multiple_input_temp);
  44.  
  45. vector<string> first_multiple_input = split(rtrim(first_multiple_input_temp));
  46.  
  47. int n = stoi(first_multiple_input[0]);
  48.  
  49. int m = stoi(first_multiple_input[1]);
  50.  
  51. string arr_temp_temp;
  52. getline(cin, arr_temp_temp);
  53.  
  54. vector<string> arr_temp = split(rtrim(arr_temp_temp));
  55.  
  56. vector<int> arr(n);
  57.  
  58. for (int i = 0; i < n; i++) {
  59. int arr_item = stoi(arr_temp[i]);
  60.  
  61. arr[i] = arr_item;
  62. }
  63.  
  64. string brr_temp_temp;
  65. getline(cin, brr_temp_temp);
  66.  
  67. vector<string> brr_temp = split(rtrim(brr_temp_temp));
  68.  
  69. vector<int> brr(m);
  70.  
  71. for (int i = 0; i < m; i++) {
  72. int brr_item = stoi(brr_temp[i]);
  73.  
  74. brr[i] = brr_item;
  75. }
  76.  
  77. int total = getTotalX(arr, brr);
  78.  
  79. fout << total << "\n";
  80.  
  81. fout.close();
  82.  
  83. return 0;
  84. }
  85.  
  86. string ltrim(const string &str) {
  87. string s(str);
  88.  
  89. s.erase(
  90. s.begin(),
  91. find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
  92. );
  93.  
  94. return s;
  95. }
  96.  
  97. string rtrim(const string &str) {
  98. string s(str);
  99.  
  100. s.erase(
  101. find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
  102. s.end()
  103. );
  104.  
  105. return s;
  106. }
  107.  
  108. vector<string> split(const string &str) {
  109. vector<string> tokens;
  110.  
  111. string::size_type start = 0;
  112. string::size_type end = 0;
  113.  
  114. while ((end = str.find(" ", start)) != string::npos) {
  115. tokens.push_back(str.substr(start, end - start));
  116.  
  117. start = end + 1;
  118. }
  119.  
  120. tokens.push_back(str.substr(start));
  121.  
  122. return tokens;
  123. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int getTotalX(std::vector<int>, std::vector<int>)’:
prog.cpp:20:16: error: ‘gcd’ was not declared in this scope
     int ucln = gcd(b[0],b[1]);
                ^~~
prog.cpp:20:16: note: suggested alternative: ‘gcvt’
     int ucln = gcd(b[0],b[1]);
                ^~~
                gcvt
prog.cpp:25:16: error: ‘lcm’ was not declared in this scope
     int bcnn = lcm(a[0],a[1]);
                ^~~
prog.cpp:31:13: error: expected ‘}’ before ‘else’
             else res++;
             ^~~~
prog.cpp:27:24: note: to match this ‘{’
         if(bcnn<= ucln){
                        ^
prog.cpp:33:27: error: ‘i’ was not declared in this scope
         bcnn = lcm(bcnn,a[i]);
                           ^
prog.cpp:34:5: warning: no return statement in function returning non-void [-Wreturn-type]
     }
     ^
prog.cpp: At global scope:
prog.cpp:35:5: error: expected unqualified-id before ‘return’
     return res;
     ^~~~~~
prog.cpp:36:1: error: expected declaration before ‘}’ token
 }
 ^
stdout
Standard output is empty