Advertisement
Guest User

Untitled

a guest
Sep 24th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("file.in");
  8. ifstream fout("file.out");
  9.  
  10. int fib[20], counter;
  11.  
  12. void generareFibo(int n)
  13. {
  14. counter = 2;
  15.  
  16. fib[0] = 1;
  17. fib[1] = 1;
  18.  
  19. for(int i = 2;; i++, counter++)
  20. {
  21. fib[i] = fib[i - 1] + fib[i - 2];
  22. if(fib[i] >= n)
  23. break;
  24. }
  25.  
  26. }
  27.  
  28. bool calc()
  29. {
  30. int a, b;
  31. while(fin >> a >> b)
  32. {
  33. if(a < b)
  34. {
  35. int aux = a;
  36. a = b;
  37. b = aux;
  38. }
  39.  
  40. generareFibo(a);
  41.  
  42. for(int i = 0; i < counter; i++)
  43. {
  44. if(fib[i] == b)
  45. {
  46. if(fib[i + 1] == a)
  47. cout << "DA";
  48. else
  49. cout << "NU";
  50.  
  51. cout << endl;
  52. break;
  53. }
  54. if(i == counter - 1)fin >> a >> b;
  55. cout << "NU" << endl;
  56. }
  57. }
  58. }
  59.  
  60. int main()
  61. {
  62. calc();
  63. return 1;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement