Skip to content

Instantly share code, notes, and snippets.

@FantasticJZI
Last active October 16, 2023 09:07
Show Gist options
  • Save FantasticJZI/41506217d3ce793ed05a74aaac0576ee to your computer and use it in GitHub Desktop.
Save FantasticJZI/41506217d3ce793ed05a74aaac0576ee to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//判斷二進制的進位次數
int carryTime(long int input)
{
if(input%2==1)
return 0;
if(input%4==1)
return 1;
for(int i=31;i>=1;i--)
{
if(input%(long int)pow(2,i)==0)
return i;
}
}
void main()
{
long int N;
while(scanf("%ld",&N)!=EOF)
{
if(N==0)
break;
else
printf("%d\n",carryTime(N+1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment