Advertisement
a53

fibosir_90p

a53
Nov 28th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3. #define Nmax 500
  4. #define Rmax 420000
  5. using namespace std;
  6. int A[Nmax], B[Nmax], C[Nmax], Rez[Rmax],i, N, M, K;
  7.  
  8. void adun(){
  9. int i=1, t=0;
  10. while (i<=A[0] || i<= B[0] || t>0)
  11. {
  12. t= A[i] + B[i] + t;
  13. C[i] = t % 10;
  14. t/=10;
  15. i++;
  16. }
  17. C[0] = i-1;
  18. }
  19.  
  20. void swp (int X[Nmax], int Y[Nmax]){
  21. int i;
  22. for (i=1; i<=Y[0]; i++) X[i]=Y[i];
  23. X[0]= Y[0];
  24. }
  25.  
  26.  
  27. void taie(){
  28.  
  29. int i=1, Nr=0, tai=0, Max , j, poz;
  30. i=1;
  31. for(i=1; i<=Rez[0] && Nr<=M; i++){
  32. Max = Rez[i];
  33. for (j=1; j<=M - Nr; j++)
  34. if (Rez[i + j * K] > Max) {
  35. Max = Rez[i + j * K];
  36. poz=i + j * K;
  37. tai=j;
  38. }
  39. if (Max > Rez[i]&& Nr<M){
  40. i = poz;
  41. Nr += tai;
  42. }
  43. printf("%d",Rez[i]);
  44. }
  45.  
  46.  
  47. }
  48.  
  49. int main()
  50. {
  51.  
  52. freopen("fibosir.in","r",stdin);
  53. freopen("fibosir.out","w",stdout);
  54. scanf("%d %d %d", &N, &M, &K);
  55. A[0]=1; A[1]=1; B[0]=1; B[1]=1; Rez[0]=2; Rez[1]=1; Rez[2]=1;
  56. for(i=3; i<=N; i++){
  57. adun(); swp(A,B); swp(B,C);
  58. reverse(C+1, C+C[0]+1);
  59. for (int t=1; t<=C[0]; t++) Rez[Rez[0]+t]=C[t];
  60. Rez[0]+=C[0];
  61. }
  62.  
  63. taie ();
  64.  
  65. printf("\n");
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement