Advertisement
a53

Pavare3

a53
Nov 24th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <fstream>
  2. #define NMax 1000
  3. using namespace std;
  4. typedef int Huge[NMax+3];
  5.  
  6. void Subtract(Huge A, Huge B) /// A <- A-B
  7. { int i, T=0;
  8. for (i=B[0]+1;i<=A[0];) B[i++]=0;
  9. for (i=1;i<=A[0];i++)
  10. A[i]+= (T=(A[i]-=B[i]+T)<0) ? 10 : 0;
  11. while (!A[A[0]]&&A[0]>1) A[0]--;
  12. }
  13.  
  14. void Mult(Huge H, unsigned long X) /// H <- H*X
  15. { int i;
  16. unsigned long T=0;
  17.  
  18. for (i=1;i<=H[0];i++)
  19. { H[i]=H[i]*X+T;
  20. T=H[i]/10;
  21. H[i]=H[i]%10;
  22. }
  23. while (T) /* Cat timp exista transport */
  24. { H[++H[0]]=T%10;
  25. T/=10;
  26. }
  27. }
  28.  
  29. void Copy(Huge A,Huge B) /// A<-B
  30. {
  31. for(int i=0;i<=B[0];++i)
  32. A[i]=B[i];
  33. }
  34.  
  35. int main()
  36. {
  37. int n;
  38. ifstream f("pavare.in");
  39. f>>n;
  40. f.close();
  41. Huge P,P0,P1;
  42. P[0]=0,P0[0]=1,P0[1]=1,P1[0]=1,P1[1]=3;
  43. int i=0,cn=n;
  44. while(n)
  45. P[++i]=n%10,n/=10,++P[0];
  46. for(int i=2;i<=cn;++i)
  47. Copy(P,P1),Mult(P,4),Subtract(P,P0),Copy(P0,P1),Copy(P1,P);
  48. ofstream g("pavare.out");
  49. for(int i=P[0];i>0;--i)
  50. g<<P[i];
  51. g.close();
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement