Advertisement
Patrickmeme

Reorganizare 2- formula

Feb 17th, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. ifstream cin("reorganizare2.in");
  5. ofstream cout("reorganizare2.out");
  6.  
  7. int main()
  8. {
  9.     long long n,inceput,sfarsit,put,cif,ccif;
  10.     cin>>n;
  11.     inceput=(n-1)*n/2+1;
  12.     sfarsit=n*(n+1)/2;
  13.     ///prima parte
  14.     put=9;
  15.     cif=1;
  16.     while(put*cif<=inceput){
  17.         inceput-=put*cif;
  18.         put*=10;
  19.         cif++;
  20.     }
  21.     ccif=(inceput-1)%cif+1;
  22.     inceput=put/10+inceput/cif;
  23.     ccif++;
  24.     while(ccif<cif){
  25.         inceput/=10;
  26.         ccif++;
  27.     }
  28.     cout<<inceput%10<<" ";
  29.     ///a doua parte
  30.     put=9;
  31.     cif=1;
  32.     while(put*cif<=sfarsit){
  33.         sfarsit-=put*cif;
  34.         put*=10;
  35.         cif++;
  36.     }
  37.     ccif=(sfarsit-1)%cif+1;
  38.     sfarsit=put/10+sfarsit/cif;
  39.     while(ccif<cif){
  40.         sfarsit/=10;
  41.         ccif++;
  42.     }
  43.     cout<<sfarsit%10;
  44.     ///printf("%d ",sfarsit%10);
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement