Advertisement
Guest User

cmmdcsecv

a guest
Dec 14th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("cmmdcsecv.in");
  6. ofstream fout("cmmdcsecv.out");
  7.  
  8. int a[100003],n;
  9. int b[1001],prime[1001],k;
  10.  
  11. void ciur(int n)
  12. {
  13. int i,j;
  14. for(i=2; i*i<=n; i++)
  15. if(b[i]==0)
  16. for (j=i*i; j<=n; j=j+i)
  17. b[j]=1;
  18. prime[1]=2;
  19. k=1;
  20. for(i=3; i<=n; i+=2)
  21. if(b[i]==0) prime[++k]=i;
  22. }
  23.  
  24. void citire()
  25. {
  26. fin >> n;
  27. for (int i=1;i<=n;i++)
  28. fin >> a[i];
  29. }
  30.  
  31. /// ret. lungimea maxima a unei secvente de numere
  32. /// toate divizibile cu P
  33. int lungmax(int P)
  34. {
  35. int l=0,lgmax=0;
  36. for (int i=1;i<=n;i++)
  37. {
  38. if (a[i]%P==0)l++;
  39. else l=0;
  40. lgmax=max(l,lgmax);
  41. }
  42. return lgmax;
  43. }
  44.  
  45. void solutie()
  46. {
  47. int P,i,l,lmax=0;
  48. for (i=1;i<=k;i++)
  49. {
  50. l=lungmax(prime[i]);
  51. lmax=max(lmax,l);
  52. }
  53. fout << lmax << "\n";
  54. fout.close();
  55. }
  56.  
  57. int main()
  58. {
  59.  
  60. citire();
  61. ciur(1000);
  62. solutie();
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement