You are viewing a single comment's thread. Return to all comments →
My c++ sol getting timeout in 2 cases can anyone help!!!!please..
#include <iostream> using namespace std; bool isPrime(int n) { if(n==1) return false; if(n==2) return true; for (int i = 2; i*i <= n; ++i) { if(n%i==0) return false; } return true; } int main() { int n,testcase; cin>>testcase; for(int i=0;i<testcase;++i) { cin>>n; int track=0; int* arr=new int[n]; for (int i = 0; i < n; ++i) { arr[i]=i+1; } for (int i = 0; i < n; ++i) { if(isPrime(arr[i])&&arr[i]!=-1) { ++track; arr[i]=-1; } } if(track%2==0) cout<<"Bob\n"; else cout<<"Alice\n"; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Alice and Bob's Silly Game
You are viewing a single comment's thread. Return to all comments →
My c++ sol getting timeout in 2 cases can anyone help!!!!please..