Advertisement
a53

nthodd

a53
Feb 23rd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #define N 201
  3. using namespace std;
  4. typedef int Huge[N];
  5.  
  6. void AtribValue(Huge H,unsigned long long int X)
  7. {
  8. H[0] = 0;
  9. while(X)
  10. ++H[0],H[H[0]]=X%10,X/=10;
  11. }
  12.  
  13. void Mult(Huge H,int X) /// H <- H*X
  14. {
  15. int T=0;
  16. for(int i=1;i<=H[0];++i)
  17. H[i]=H[i]*X+T,T=H[i]/10,H[i]=H[i]%10;
  18. while (T) /// Cat timp exista transport
  19. H[++H[0]]=T%10,T/=10;
  20. }
  21.  
  22. void Subtract(Huge A,Huge B) /// A <- A-B
  23. {
  24. int T=0;
  25. for(int i=B[0]+1;i<=A[0];)
  26. B[i++]=0;
  27. for(int i=1;i<=A[0];++i)
  28. A[i]+=(T=(A[i]-=B[i]+T)<0)
  29. ? 10:0;
  30. while(!A[A[0]])
  31. A[0]--;
  32. }
  33.  
  34. void Afis(Huge A)
  35. {
  36. for(int i=A[0];i>0;--i)
  37. cout<<A[i];
  38. cout<<'\n';
  39. }
  40.  
  41. int main()
  42. {
  43. unsigned long long int n;
  44. cin>>n;
  45. Huge A;
  46. AtribValue(A,n);
  47. Mult(A,2);
  48. Huge U;
  49. AtribValue(U,1);
  50. Subtract(A,U);
  51. Afis(A);
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement