fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. std::vector<std::size_t> GanerateArray(std::size_t N){
  5.  
  6. std::vector<std::size_t> vec;
  7. std::size_t undefined;//不定値
  8.  
  9. vec.push_back(undefined);//不備??昇順なので、0か1の可能性。
  10. vec.push_back(1);//絶対条件
  11. vec.push_back(2);//seed??
  12.  
  13. for (std::size_t i = 2; i < N; i++)
  14. {
  15. for (std::size_t j = 0; j < vec[i]; j++)
  16. {
  17. vec.push_back(i);
  18. if (vec.size() > N) return vec;
  19. }
  20. }
  21.  
  22. return vec;
  23. }
  24.  
  25. int main(){
  26. auto A = GanerateArray(1000);
  27.  
  28. std::cout << "N=10:" << A[10] << std::endl;
  29. std::cout << "N=100:" << A[100] << std::endl;
  30. std::cout << "N=1000:" << A[1000] << std::endl;
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
N=10:5
N=100:21
N=1000:86