Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define endl "\n"
- #define ll long long
- #define PI acos(-1.0)
- #define test cout<<"\n****\n"
- #define LCM(a,b) ((a/__gcd(a,b))*b)
- #define READ(f) freopen(f, "r", stdin)
- #define WRITE(f) freopen(f, "w", stdout)
- #define precise fixed(cout);cout<<setprecision(20)
- #define fast ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- bool isPrime(int num){
- if(num==1 || num==0){
- return false;
- }
- for(int i=2;i*i<=num;i++){
- if(num%i==0){
- return false;
- }
- }
- return true;
- }
- #define valid(next_x,next_y) next_x>=0 && next_x<row && next_y>=0 && next_y<column
- int fx[]={+1,-1,+0,+0};
- int fy[]={+0,+0,+1,-1}; /*for horizontally and vertically*/
- int main(){
- int row,column;
- cin>>row>>column;
- int arr[row][column];
- for(int i=0;i<row;i++){
- for(int j=0;j<column;j++){
- cin>>arr[i][j];
- }
- }
- cout<<endl;
- for(int i=0;i<row;i++){
- for(int j=0;j<column;j++){
- printf("%2d ",arr[i][j]);
- }
- cout<<endl;
- }
- cout<<endl;
- for(int i=0;i<row;i++){
- for(int j=0;j<column;j++){
- if(isPrime(arr[i][j])) {
- for (int k = 0; k < 4; k++) {
- int next_x = i + fx[k];
- int next_y = j + fy[k];
- if (valid(next_x, next_y)) {
- arr[next_x][next_y] = 0;
- }
- }
- }
- }
- }
- for(int i=0;i<row;i++){
- for(int j=0;j<column;j++){
- printf("%2d ",arr[i][j]);
- }
- cout<<endl;
- }
- return 0;
- }
- *************************************************************************************
- *************************************************************************************
- #include<bits/stdc++.h>
- using namespace std;
- #define endl "\n"
- #define ll long long
- #define PI acos(-1.0)
- #define test cout<<"\n****\n"
- #define LCM(a,b) ((a/__gcd(a,b))*b)
- #define READ(f) freopen(f, "r", stdin)
- #define WRITE(f) freopen(f, "w", stdout)
- #define precise fixed(cout);cout<<setprecision(20)
- #define fast ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
- bool isPrime(int num){
- if(num==1 || num==0){
- return false;
- }
- for(int i=2;i*i<=num;i++){
- if(num%i==0){
- return false;
- }
- }
- return true;
- }
- #define valid(next_x,next_y) next_x>=0 && next_x<row && next_y>=0 && next_y<column
- int fx[]={+1,-1,+0,+0,-1,+1,-1,+1};
- int fy[]={+0,+0,+1,-1,+1,+1,-1,-1}; /* for horizontally,vertically and diagonally*/
- int main(){
- int row,column;
- cin>>row>>column;
- int arr[row][column];
- for(int i=0;i<row;i++){
- for(int j=0;j<column;j++){
- cin>>arr[i][j];
- }
- }
- cout<<endl;
- for(int i=0;i<row;i++){
- for(int j=0;j<column;j++){
- printf("%2d ",arr[i][j]);
- }
- cout<<endl;
- }
- cout<<endl;
- for(int i=0;i<row;i++){
- for(int j=0;j<column;j++){
- if(isPrime(arr[i][j])) {
- for (int k = 0; k < 8; k++) {
- int next_x = i + fx[k];
- int next_y = j + fy[k];
- if (valid(next_x, next_y)) {
- arr[next_x][next_y] = 0;
- }
- }
- }
- }
- }
- for(int i=0;i<row;i++){
- for(int j=0;j<column;j++){
- printf("%2d ",arr[i][j]);
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement