# Help me in solving FIZZBUZZ2305 problem

### My issue

my code gives W.A. for 2nd test case what’s the issue here include <bits/stdc++.h>
define ll long long
using namespace std;
bool isprime(ll n){
for(int i=2;i*i<=n;i++){
if(n%i==0) return false;
}
return true;
}

int main() {
// your code goes here
ll t; cin>>t;
while(t–){
ll n; cin>>n;
ll x=0,i=0,cnt=0;
for( i=3;i<=n/2;i++){
if(isprime(i)) {cnt=1;break;}
}

`````` if(cnt) x=n/i;
else{
if(n<=2) x=0;
else if(isprime(n)) x=1; }
if(x%2) cout<<"Alice"<<endl;
else cout<<"Bob"<<endl;
}
return 0;
``````

}
can anyone please tell me??

### My code

``````#include <bits/stdc++.h>
#define ll long long
using namespace std;
bool isprime(ll n){
for(int i=2;i*i<=n;i++){
if(n%i==0) return false;
}
return true;
}

int main() {
// your code goes here
ll t; cin>>t;
while(t--){
ll n; cin>>n;
ll x=0,i=0,cnt=0;
for( i=3;i<=n/2;i++){
if(isprime(i)) {cnt=1;break;}
}

if(cnt) x=n/i;
else{
if(n<=2) x=0;
else if(isprime(n)) x=1; }
if(x%2) cout<<"Alice"<<endl;
else cout<<"Bob"<<endl;
}
return 0;
}

``````

Problem Link: FIZZBUZZ2305 Problem - CodeChef

The constraints are too high for you to check if the given number is prime in o(sqrt(n)) time.

As iceknight1093 states in his editorial:

Let p be an odd prime factor of N.
Then, note that p is also an odd prime factor of N−p, since N is itself a multiple of p.

Corrected o(1) Code:

``````#include <iostream>
using namespace std;

int main() {
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
if (n > 1 && n & 1)
cout<<"Alice\n";
else
cout<<"Bob\n";
}
}
``````

Another Corrected Code That’s almost as efficient as o(1):

``````#include<bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
if (n <= 1) {
return false;
}
if (n <= 3) {
return true;
}
if (n % 2 == 0 || n % 3 == 0) {
return false;
}
for (int i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0) {
return false;
}
}
return true;
}

int solve(int n){
if(n%2 == 0) return 1; // bob
if(isPrime(n)) return 0; // alice
for(int p=3;p<=n;p+=2){
if((n%p == 0) && (isPrime(p))) return 0;//alice
}
return 1;
}

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;  cin>>t;
while(t--){
int n;  cin>>n;
bool result = solve(n);
if(result == false) cout<<"Alice\n";
else cout<<"Bob\n";
}
return 0;
}
``````