What's wrong with this code?

#include
using namespace std;
bool rem(int n){
int check=0;
for(int i = 1; i<=n; i++){
if(n%i == 0){
check = check + 1;
}
}
return(check == 2)?true:false;
}

int main() {
// your code goes here
int t;
cin >> t;
int anst = 1;
while(t–){
int ans; int count =0;
int x , y;
cin >> x >> y;
int i = 1;
ans = x + y+i;

    while(rem(ans) != true) {
        anst = anst + 1;
        ans = ans + 1;


    }
    cout << anst << endl;


}
return 0;

}

what issue you faced with this code can you elaborate
and better if you provide problem link too

CodeChef | Competitive Programming | Participate & Learn | CodeChef
the status was wrong answer although the testcases were correct

you declare value of anst=1
outside of while loop and its increasing until t test case are running
means you have to set value anst=1
after every new input

like this

int anst = 1;
while(t–){
int ans; int count =0;
int x , y;
cin>>x>>y;
anst=1;
//remaining code
}

i implement your code with little modification and its accepted https://www.codechef.com/viewsolution/49652163

1 Like

Thank you for your help. It worked.