Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include<cstdio>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5.  
  6. int s[1001],f[1002];
  7.  
  8. int prim(int n)
  9. {
  10. int d,nrd=0;
  11. if(n%2==0 && n>2)
  12. return 0;
  13. for(d=3; d*d<=n; d+=2)
  14. {
  15. if(n%d==0)
  16. {
  17. return 0;
  18. }
  19. }
  20. return 1;
  21.  
  22. }
  23. int main()
  24. {
  25. int i,j,n,maxi=0,m,aux,nr;
  26. freopen ("memory004.in","r+",stdin);
  27. freopen ("memory004.out","w+",stdout);
  28. scanf("%d %d ",&m,&n);
  29. for(i=1;i<=m;i++)
  30. {
  31. for(j=1;j<=n;j++)
  32. {
  33. scanf("%d ",&aux);
  34. if(aux<2)
  35. continue;
  36. if(prim(aux)==1)
  37. {
  38. if(s[j]==i-1)
  39. {
  40. s[j]++;
  41. }
  42. else
  43. {
  44. f[j]++;
  45.  
  46. }
  47. if(maxi<max(s[j],f[j]))
  48. {
  49. maxi=max(s[j],f[j]);
  50. }
  51. }
  52. else
  53. {
  54. f[j]=0;
  55. }
  56. }
  57. }
  58. // cout<<maxi;
  59. nr=0;
  60. for(j=1;j<=n+1;j++)
  61. {
  62. nr+=s[j]+f[j-1];
  63. if(maxi<nr)
  64. {
  65. maxi=nr;
  66. }
  67. if(s[j]!=m)
  68. {
  69. nr=0;
  70. }
  71.  
  72. }
  73. printf("%d",maxi);
  74.  
  75. return 0;
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement