fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. typedef std::vector<std::pair<int, int>> DType;
  6.  
  7. DType MakeHoge(std::size_t X, std::size_t Y){
  8. double A = Y / static_cast<double>(X);//x=0 is die!LOL!!
  9. DType R;
  10. double YY = Y;
  11. double XX = X;
  12. for (std::size_t i = 1; i <= X; i++){
  13. YY = i*A;
  14. if (YY == std::ceil(YY)){
  15. XX = i;
  16. break;
  17. }
  18. }
  19. for (std::size_t i = 1; i*XX <= X; i++){
  20. R.push_back(std::make_pair(i*XX, i*YY));
  21. }
  22. R.push_back(std::make_pair(X,Y));
  23.  
  24. return R;
  25. }
  26.  
  27. bool Show(DType& D){
  28. std::cout << "a=" << D.back().first << " b=" << D.back().second << std::endl;
  29. D.pop_back();
  30. for (auto& o : D) std::cout << o.first << ' ' << o.second<< std::endl;
  31.  
  32. return true;
  33. }
  34.  
  35. int main(){
  36.  
  37. auto R = MakeHoge(54, 66);
  38. Show(R);
  39.  
  40. return 0;
  41.  
  42. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
a=54 b=66
9 11
18 22
27 33
36 44
45 55
54 66