CÓïÑÔÌâÄ¿£¬2µÄN´Î·½±»3Õû³ý
ÈËÆø£º
¡¾×ÖÌ壺´ó ÖРС¡¿
·¢²¼Ê±¼ä£º2009-04-09 11:51:37
>>>>>>>>ÌáÎÊprintf("%d"n);
ÐÝ ÏÐ ¾Ó ±à ¼
>>>>>>>>ÐÝÏÐÑøÉúÍø»Ø´ð£ºÕâ¸ö´æÔÚÒç³öÎÊÌ⣬´ó¸ÅÏëÁ˸ö˼·£¬ÏȸøÄã˵һÏ£¬ÉÏ°à±È½Ï棬³ÌÐòµÈдºÃÁËÌùÉÏÀ´¡£
Ä㽨Á¢Êý×énum,ÓÃÓÚ´æ´¢2^n,Êý×énum[0]´æ´¢2^nµÄ¸ö룬num[1]´æ´¢2^nµÄʮ룬ÒÔ´ËÍÆÏÂÈ¥£¬¹Ø¼üµÄ˼·ÔÚÕâÀһ¸öÕûÊýi£¬Èç¹ûËüµÄ¸÷λ¼ÓºÍΪ3µÄ±¶Êý£¬ÄÇôËü¿ÉÒÔ±»3Õû³ý¡£ÕâÑùÖ»ÒªÊý×énumµÄ¸÷¸öÔªËØÏà¼ÓµÄºÍΪ3µÄ±¶Êý£¬ÄÇôÕâ¸önÒ²¾Í¼ÆËã³öÀ´ÁË¡£ÕâÀïnum[0]¿ÉÒÔ´Ó2¿ªÊ¼£¬Ã¿´În+1,Ôò´Ónum[0]¿ªÊ¼num[k]*2;if(num[k]*2>9){num[k+1]+=1;num[k]=num[k]*2-10;},×îºóÒ»¸öfor´Ónum[0]¼Óµ½num[m]£¨num[m+1]ΪÊý×é½áÊø·û¡®\0¡¯£©¾ÍÊÇiµÄ¸÷λ¼ÓºÍÁË
Õâ¸öÊÇ´¿Ëã·¨µÄÌâÄ¿£¬ÓõÄÊÇÓüӷ¨À´½µµÍ³Ë·¨£¨»òÕß˵ÊÇÚ¤¼¶ÔËËãµÄÊýÁ¿¼¶£©µÄ·½·¨£¬Í¬Ê±ÎªÁ˽â¾öcÓïÑÔÒç³öµÄÎÊÌ⣬ֻÄÜÓÃÊý×éÀ´×ö¡£
Â¥Ö÷ÒªÊÇ¿´Ã÷°×ÁË£¬¿ÉÒÔÔÙ˼¿¼ÏÂÁ½¸ö´óÊýÏà³ËµÄËã·¨£¬±ÈÈçÁ½¸ö20볤µÄÊý×ÖÏà³Ë£¬ÉõÖÁ¸ü³¤µÄÁ½¸öÊýÏà³Ð£¬»¹ÓÐÏà³ýËã·¨£¬ºÜÓÐÒâ˼µÄ£º£©
=============================================
#include <stdio.h>
#define N 10000//¶¨Òå2^n×î´ó³¤¶È
main()
{
char num[N];
int sum,i,j,n;
i=0;
n=1;
sum=2;
num[0]=2;
num[1]='}';//2^n½áÊø·û
while(j!=0&&i<=N)//ÅжÏ2^n¸÷λÊý×Ö¼ÓºÍÊÇ·ñÄܱ»3Õû³ý
{
sum=0;
// printf("process!!\n");
n++;
for(;num[i]!='}';i++)
num[i]*=2;
for(i=0;num[i]!='}';i++)
if(num[i]>9)
{//Ïò¸ßλ½øλ
if(num[i+1]=='}')
{
num[i+2]='}';
num[i+1]=1;
num[i]-=10;
}
else
{
num[i+1]+=1;
num[i]-=10;
}
}
for(i=0;num[i]!='}';i++)
{
printf("num[%d]:",i);
printf("%d\n",num[i]);
}
for(i=0;num[i]!='}';i++)
sum+=num[i];
j=sum%3;//2^n¸÷λÊý×Ö¼ÓºÍÄ£3
printf("sum:%d\n",sum);
printf("n:%d\n",n);
printf("j:%d\n",j);
}
return 0;
}
=============================================
ÕâÀïÓÃÁË¡°}¡±À´´úÌæ¡°\0¡±
³ÌÐòÔËÐÐÆðÀ´ºó£¬ÎÞ·¨Ìø³öwhileÑ»·£¬ËµÃ÷ûÓÐÕâÑùµÄn´æÔÚ
´ÓÊýѧµÄ½Ç¶ÈÀ´·ÖÎö£¬2^n´Ón=0¿ªÊ¼£¬Ä£3ÓàÊýΪ1£»n=1,Ä£3ÓàÊýΪ2£»n=2£¬Ä£3ÓàÊýΪ1£»Ã¿´În+1,ÔòÓàÊýҲΪÔÀ´2±¶£¬¶øµ±ÓàÊýΪ4ʱ£¬Ï൱ÓÚÄ£3ÓàÊýΪ1¡£ÒÔ´Ë·´¸´ÏÂÈ¥£¬½áÂÛÊÇ2^nÊDz»Äܱ»3Õû³ýµÄ...
Ì«Òź¶ÁË£¬Ì«¿ÉÅÂÁË~~~~
°Ñ³ÌÐòÔÙÐÞ¸ÄÈçÏÂ
=============================================
#include <stdio.h>
#define N 50//¶¨Òå2^n×î´ó³¤¶È
main()
{
char num[N];
int sum,i,j,n;
i=0;
n=1;
sum=2;
num[0]=2;
num[1]='}';//2^n½áÊø·û
while(j!=0&&i<N)//ÅжÏ2^n¸÷λÊý×Ö¼ÓºÍÊÇ·ñÄܱ»3Õû³ý
{
sum=0;
// printf("process!!\n");
n++;
for(i=0;num[i]!='}';i++)
num[i]*=2;
for(i=0;num[i]!='}';i++)
if(num[i]>9)
{//Ïò¸ßλ½øλ
if(num[i+1]=='}')
{
num[i+2]='}';
num[i+1]=1;
num[i]-=10;
}
else
{
num[i+1]+=1;
num[i]-=10;
}
}
for(i=0;num[i]!='}';i++)
{
printf("num[%d]:",i);
printf("%d\n",num[i]);
}
for(i=0;num[i]!='}';i++)
sum+=num[i];
j=sum%3;//2^n¸÷λÊý×Ö¼ÓºÍÄ£3
if(j==0)
printf("2^%dÄܱ»3Õû³ý!\n",n);
printf("sum:%d\n",sum);
printf("n:%d\n",n);
printf("j:%d\n",j);
}
printf("¶¨Ò巶ΧÄÚµÄ2^n²»Äܱ»3Õû³ý!\n");
printf("ÇëÐÞ¸ÄËù¶¨Òå2^n×î´ó·¶Î§ºóÖØÊÔ!\n");
return 0;
}
=============================================
¡Ô ²é¿´¡¢·¢±íÆÀÂÛ ¡Ô