对于任意大于一的自然数n,若n为奇数,则将n变为3n+1,否则变为n的一半,经过若干次这样的变换,一定会使n变为1.求输出变换的次数,注 要求次数要对3取余;例如3->10->5->16->8->4->2->1 变换了7次,对3取余的1; n<=109
3 2
1 1
<a target=_blank href="http://acm.nyist.net/JudgeOnline/profile.php?userid=TC_%E5%BE%90%E5%BC%BA" style="text-decoration: none; color: rgb(55, 119, 188);">#include<stdio.h>
#include<string.h>
int main()
{
int n,sum;
while(scanf("%d",&n)!=EOF)
{
sum=0;
while(n!=1)
{
if(n%2==1)
n=3*n+1;
else
n/=2;
sum++;
}
printf("%d\n",sum%3);
}
return 0;
}</a>
原文:http://blog.csdn.net/hdd871532887/article/details/41392823