8/29/2011

f(N) counts number of '1'. For example f(13) = 6. So f(1)=1. What next number do satisfy the rule?



f(N) counts number of '1'. For example f(13) = 6. So f(1)=1. What next number do satisfy the rule?


---------------------------------------------------


์–‘์ˆ˜ n์— ๋Œ€ํ•ด์„œ 1๊ณผ n ์‚ฌ์ด์— 1์ด ๋‚˜์˜ค๋Š” ํšŸ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ํ•จ์ˆ˜๋ฅผ f(n)์ด๋ผ๊ณ  ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด f(13)=6์ด๋‹ค. f(n)=n์ด ๋˜๋Š” ์ฒซ๋ฒˆ์งธ ์–‘์ˆ˜๋Š” 1์ด๋‹ค. ๋‘๋ฒˆ์งธ ์–‘์ˆ˜๋Š” ๋ฌด์—‡์ธ๊ฐ€?


5 comments:

  1. This is my code.
    Let's compare to each code.
    Bye Bye~ ^^

    int CountOne(int input)
    {
    int count =0;
    while(1)
    {
    if( input%10 == 1)
    count++;
    input = input/10;

    if(input == 0)
    break;
    }

    return count;
    }


    int main()
    {
    int i=2;
    int count=1;

    while(1)
    {

    count += CountOne(i);

    if( i == count)
    break;

    i=i+1;

    }


    printf("f(%d) = %d\n", i, count);

    return 0;
    }

    ReplyDelete
  2. Anonymous30/8/11 00:16

    JeKang's code:

    #include

    void main()
    {
    unsigned long Num, End, Temp;

    Num=0;
    End=0;

    while(Num<=1 || Num!=End){
    Num+=1;
    Temp=Num;

    while(Temp!=0){
    if(Temp%10==1) End+=1;
    Temp=(unsigned long)(Temp/10);
    }

    }
    printf("์ž…๋ ฅ๊ฐ’ Num = %d\n๊ฒฐ๊ณผ๊ฐ’ End = %d\n",Num,End);
    }

    ReplyDelete
  3. ์ œ๊ฐ•์•„ ์†Œ์Šค ์ž˜ ์งฐ๋„ค..
    ๋‚ด๊ฐ€ ๋ณผ๋•Œ๋Š”, while๋ฌธ ์กฐ๊ฑด์ด ์กฐ๊ธˆ ๋ณต์žกํ•ด์„œ ๋‚˜์ค‘์— ๋ณด๋ฉด ์ดํ•ด๊ฐ€ ์‰ฝ๊ฒŒ ์•ˆ๊ฐˆ ๊ฒƒ ๊ฐ™๊ณ ..
    while๋ฌธ ์•ˆ์— while๋ฌธ์€ ํŠน์ • ์ผ๋งŒ ํ•˜๋‹ˆ๊น ํ•จ์ˆ˜๋กœ ๋งŒ๋“ค๋ฉด ์†Œ์Šค๊ฐ€ ๋” ๊ฐ„๊ฒฐํ•ด ์งˆ ๊ฒƒ ๊ฐ™๋‹ค.
    ์ž˜ํ–ˆ๋„ค..
    Good job~!!

    ReplyDelete
  4. Anonymous1/9/11 02:46

    JeKang :

    ๋„ค ํ•จ์ˆ˜๋กœ๋„ ๋งŒ๋“ค์–ด ๋ณผ๊ป˜์š”. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค~

    ReplyDelete
  5. Anonymous2/9/11 03:21

    ๋ฏผํ˜„๊ทœ

    #include
    #include

    int fun(char* a);

    void main()
    {
    int d;
    int p=0;
    int i=0;
    char a[20]={0,};
    printf("์ˆซ์ž์ž…๋ ฅํ•˜์„ธ์š”:");
    scanf("%d",&d);

    for(i=0;i<=d;i++)
    {
    itoa(i,a,10);
    p=p+fun(a);
    if(p==i)
    printf("%d\n",p);

    }

    }

    int fun(char* a)
    {
    int i=0;
    int count=0;
    for(i=0;i<= 20 ;i++)
    {
    if(a[i]=='1') count+=1;
    }
    return count;
    }

    ReplyDelete