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이다. 두번째 양수는 무엇인가?


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

Post a Comment

Popular posts from this blog

OpenCV Stitching example (Stitcher class, Panorama)

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Real-time N camera stitching Class.

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Optical Flow sample source code using OpenCV

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)

(OpenCV Study) calcOpticalFlowFarneback example source code ( dense optical flow )

yuv422(YUYV) to RGB and RGB to yuv422(YUYV), (Using OpenCV and TBB)

OpenCV Drawing Example, (line, circle, rectangle, ellipse, polyline, fillConvexPoly, putText, drawContours)