My issue
please provide me the solution for this problem
My code
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
if (n <= 1) {
return false;
}
for (int i = 2; i * i <= n; ++i) {
if (n % i == 0) {
return false;
}
}
return true;
}
int nearestPrime(int n) {
for (int i = n; i >= 2; --i) {
if (isPrime(i)) {
return i;
}
}
// If no prime is found (unlikely for positive n), return -1 or handle it accordingly
return -1;
}
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
int h;
cin>>h;
int rp=1,sp;
int p=nearestPrime(h);
int r=h-p;
int d=h-p;
int count=1;
for(int rp=1;rp<=d;rp*=2){
r=r-rp;
count++;
}
if(r<0){
cout<<-1<<endl;
}
else
cout<<count<<endl;
}
return 0;
}
Problem Link: Monsters Practice Coding Problem - CodeChef