fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. std::vector<int> GenerateArray(std::size_t N){
  5. std::vector<int> vec;
  6.  
  7. vec.push_back(0);
  8. vec.push_back(1);
  9. //vec.push_back(2);
  10.  
  11. for (std::size_t i = 1; i < N; i++)
  12. {
  13. vec.push_back(1 + vec[i + 1 - vec[vec[i]]]);
  14. if (vec.size() > N) return vec;
  15. }
  16. return vec;
  17. }
  18.  
  19. int main(){
  20. auto R = GenerateArray(1000);
  21.  
  22. std::cout <<"N=10:"<< R[10] << std::endl;
  23. std::cout <<"N=100:"<< R[100] << std::endl;
  24. std::cout <<"N=1000:"<< R[1000] << std::endl;
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
N=10:5
N=100:21
N=1000:86