# Optimal way for the remainder [closed]

I want to know if for any base the most significant digit is 1 or not. Here is the code:

for(int i=3;i<=a;i++)
{
int x = i;
int r = a;
while(r/x)
{
r = r/x;
}
int rem = r%x;
if(r==1)
{
count++;
}
}


is there any optimal way to replace the while loop nested in the for loop.

• I want to know if for any base the most significant digit is 1 or not it is, for more than half of your values for i (a/2 < i ≤ a). You might put your goal near the top of the post and have the title reflect it. Dec 6 '16 at 12:21
• What is your code trying to accomplish? It appears to be counting something. Also, you should probably replace your code with pseudocode. Dec 6 '16 at 12:36
• Sorry, but optimizing your code is off-topic here. Dec 6 '16 at 20:00
• @DavidRicherby It's about getting an algorithm with better running time. Dec 6 '16 at 22:16