Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. ifstream fin ("matrice.in");
  5. ofstream fout ("matrice.out");
  6. int n, v[51][51];
  7. void afisare()
  8. {
  9. for(int i=1;i<=n;i++)
  10. {
  11. for(int j=1;j<=n;j++)
  12. {
  13. fout<<v[i][j]<<" ";
  14. }
  15. fout<<'\n';
  16. }
  17. }
  18. bool prim(int n)
  19. {
  20.  
  21. if(n%2==0)
  22. return false;
  23. if(n<2)
  24. return false;
  25. for(int d=1;d*d<=n;d+=2)
  26. {
  27. if(n%d==0)
  28. return false;
  29. }
  30. return true;
  31. }
  32. bool superprim(int n)
  33. {
  34. int aux=n, c=1;
  35. while(aux!=0)
  36. {
  37. aux/=10;
  38. c*=10;
  39. }
  40. // cout<<c<<" ";
  41. bool OK=false;
  42. aux=n;
  43. if(c==10)
  44. {
  45. if(prim(aux)==true)
  46. return true;
  47. else
  48. return false;
  49. }
  50. c/=10;
  51.  
  52. do
  53. {
  54. if(prim(aux)==true){
  55. OK=true;break;
  56. }
  57. // cout<<aux<<" ";
  58. aux=((aux%((c-1)*10))*10)+aux/((c-1)*10);
  59. // cout<<aux<<" ";
  60. //cout<<aux<<" ";
  61. }while(n!=aux && OK==false);
  62. return OK;
  63. }
  64.  
  65. int main()
  66. {
  67. fin>>n;
  68. for(int i=1;i<=n;i++)
  69. {
  70. for(int j=1;j<=n;j++)
  71. {
  72. fin>>v[i][j];
  73. }
  74. }
  75. for(int i=1;i<=n/2;i++)
  76. {
  77. for(int j=i+1;j<n-i+1;j++)
  78. {
  79. int aux=v[i][j];
  80. v[i][j]=v[n-i+1][j];
  81. v[n-i+1][j]=aux;
  82. }
  83. }
  84. for(int j=1;j<=n/2;j++)
  85. {
  86. for(int i=j+1;i<=n-j;i++)
  87. {
  88. if(superprim(v[i][j])==true && superprim(v[i][n-j+1])==true){
  89. int aux=v[i][j];
  90. v[i][j]=v[i][n-j+1];
  91. v[i][n-j+1]=aux;}
  92. }
  93. }
  94. //cout<<superprim(124)<<" "<<superprim(32);
  95. afisare();
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement