fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. int times=1;
  7. cin>>n;
  8. cout<<n;
  9. while(n!=1){
  10. if(n%2==0){
  11. n=n/2;
  12. }
  13. else{
  14. n=3*n+1;
  15. }
  16. times=times+1;
  17. cout<<","<<n;
  18. }
  19. cout<<endl<<"共"<<times<<"項"<<endl;
  20. return 0;
  21. }
Success #stdin #stdout 0.01s 5320KB
stdin
9999999
stdout
9999999,29999998,14999999,44999998,22499999,67499998,33749999,101249998,50624999,151874998,75937499,227812498,113906249,341718748,170859374,85429687,256289062,128144531,384433594,192216797,576650392,288325196,144162598,72081299,216243898,108121949,324365848,162182924,81091462,40545731,121637194,60818597,182455792,91227896,45613948,22806974,11403487,34210462,17105231,51315694,25657847,76973542,38486771,115460314,57730157,173190472,86595236,43297618,21648809,64946428,32473214,16236607,48709822,24354911,73064734,36532367,109597102,54798551,164395654,82197827,246593482,123296741,369890224,184945112,92472556,46236278,23118139,69354418,34677209,104031628,52015814,26007907,78023722,39011861,117035584,58517792,29258896,14629448,7314724,3657362,1828681,5486044,2743022,1371511,4114534,2057267,6171802,3085901,9257704,4628852,2314426,1157213,3471640,1735820,867910,433955,1301866,650933,1952800,976400,488200,244100,122050,61025,183076,91538,45769,137308,68654,34327,102982,51491,154474,77237,231712,115856,57928,28964,14482,7241,21724,10862,5431,16294,8147,24442,12221,36664,18332,9166,4583,13750,6875,20626,10313,30940,15470,7735,23206,11603,34810,17405,52216,26108,13054,6527,19582,9791,29374,14687,44062,22031,66094,33047,99142,49571,148714,74357,223072,111536,55768,27884,13942,6971,20914,10457,31372,15686,7843,23530,11765,35296,17648,8824,4412,2206,1103,3310,1655,4966,2483,7450,3725,11176,5588,2794,1397,4192,2096,1048,524,262,131,394,197,592,296,148,74,37,112,56,28,14,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1
共221項