Advertisement
Guest User

eeeee

a guest
Feb 28th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("pdi.in");
  6. ofstream fout("pdi.out");
  7.  
  8. int euclid(int a, int b)
  9. {
  10.     int c;
  11.     while(b)
  12.     {
  13.         c=a%b;
  14.         a=b;
  15.         b=c;
  16.     }
  17.     return a;
  18. }
  19.  
  20. int nr, vec[100000], lung[1000];
  21.  
  22. int main()
  23. {
  24.     fin>>nr;
  25.     for(int index=0; index<nr; index++)
  26.     {
  27.         fin>>vec[index];
  28.     }
  29.     for(int index=0; index<nr; index++)
  30.     {
  31.         lung[index]=1;
  32.         for(int jndex=0; jndex<index; jndex++)
  33.             if(euclid(vec[index], vec[jndex])!=1/* && lung[jndex]+1>lung[index]*/)
  34.                 lung[index]=max(lung[index], lung[jndex]+1);
  35.     }
  36.     fout<<lung[nr-1];
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement