Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. int NWD (int x, int y)
  8. {
  9. while (x!=0 && y!=0)
  10. {
  11. if (x>y)
  12. x=x%y;
  13. else
  14. y=y%x;
  15. }
  16. int s;
  17. s=x+y;
  18. return s;
  19. }
  20. int main()
  21. {
  22. int x=0, d=0, l, p=0, y=0, s=0;
  23. vector <int> tab;
  24. ifstream plik("przyklad.txt");
  25.  
  26.  
  27.  
  28. while (plik >> x)
  29. tab.push_back(x);
  30.  
  31. cout<<tab.size();
  32. for(int i=0;i<tab.size()-1;i++)
  33. {
  34. cout<<tab[i]<<endl;
  35. }
  36. l=0;
  37. for (int i=0; i<tab.size()-1; i++)
  38. {
  39. y=tab[i];
  40. for (int j=i; j<tab.size()-1; j++)
  41. {
  42. y=NWD(y, tab[j]);
  43. if (y==1){
  44.  
  45. if (j-i>l)
  46. {
  47. l=j-i;
  48. p=i;
  49. }
  50. break;
  51. }
  52.  
  53. }
  54.  
  55. }
  56. y=tab[p];
  57. for (int j=p; j<tab.size()-1; j++)
  58. {
  59. s=y;
  60. y=NWD(y, tab[j]);
  61. if (y==1)
  62. break;
  63.  
  64.  
  65. }
  66. cout << tab[p] << " " << l << " " << s;
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement