번 설명

어떤 자연수 n이 있을 때, d(n)을 n의 각 자릿수 숫자들과 n 자신을 더한 숫자라고 정의하자.
예를 들어 d(91) = 9 + 1 + 91 = 101
이 때, n을 d(n)의 제네레이터(generator)라고 한다. 위의 예에서 91은 101의 제네레이터이다.
어떤 숫자들은 하나 이상의 제네레이터를 가지고 있는데, 101의 제네레이터는 91 뿐 아니라 100도 있다.
그런데 반대로, 제네레이터가 없는 숫자들도 있으며, 이런 숫자를 인도의 수학자 Kaprekar가

셀프 넘버(self-number)라 이름 붙였다.
예를 들어 1,3,5,7,9,20,31 은 셀프 넘버 들이다.

1번 문제

1 이상이고 5000 보다 작은 모든 셀프 넘버들의 합을 구하라.

1번 답 : ________


1~9 :

d(n) = n + n = 2*n;

10~99:

d(n) = n%10 + (n-n%10*10) + 10;

100~999:

d(n) = n%100 + (n-n%100*100)%10 + (n-n%100*100-(n-n%100*100)%10*10) + n;

1000~4999:

d(n) = n%1000 + (n-n%1000*1000)%100 + (n-n%1000*1000 - (n-n%1000*1000)%100*100)%10 + (n - n%1000*1000 - (n-n%1000*1000)%100*100 - (n-n%1000*1000 - (n-n%1000*1000)%100*100)%10*10) + n;


noself[5000] = {1,};

for i =1 to 5000

gen(i) = k

noself[k] = 0;


if(noself[i]!=0)

printf("self number is %d",i);


...


Posted by 후니 유

댓글을 달아주세요:: 스팸은 정중히 사절합니다.

  1. 어렵당
    2008/08/17 15:42
    댓글 주소 수정/삭제 댓글
    어렵당
  2. 2009/10/06 11:43
    댓글 주소 수정/삭제 댓글
    Self-number : 1 3 5 7 9 20 31 42 53 64 75 86 97 108
    110 121 132 143 154 165 176 187 198 209 211 222 233
    244 255 266 277 288 299 310 312 323 334 345 356 367
    378 389 400 411 413 424 435 446 457 468 479 490 501
    512 514 525 536 547 558 569 580 591 602 613 615 626
    637 648 659 670 681 692 703 714 716 727 738 749 760
    771 782 793 804 815 817 828 839 850 861 872 883 894
    905 916 918 929 940 951 962 973 984 995 1006 1021
    1032 1043 1054 1065 1076 1087 1098 1109 1111 1122
    1133 1144 1155 1166 1177 1188 1199 1210 1212 1223
    1234 1245 1256 1267 1278 1289 1300 1311 1313 1324
    1335 1346 1357 1368 1379 1390 1401 1412 1414 1425
    1436 1447 1458 1469 1480 1491 1502 1513 1515 1526
    1537 1548 1559 1570 1581 1592 1603 1614 1616 1627
    1638 1649 1660 1671 1682 1693 1704 1715 1717 1728
    1739 1750 1761 1772 1783 1794 1805 1816 1818 1829
    1840 1851 1862 1873 1884 1895 1906 1917 1919 1930
    1941 1952 1963 1974 1985 1996 2007 2022 2033 2044
    2055 2066 2077 2088 2099 2110 2112 2123 2134 2145
    2156 2167 2178 2189 2200 2211 2213 2224 2235 2246
    2257 2268 2279 2290 2301 2312 2314 2325 2336 2347
    2358 2369 2380 2391 2402 2413 2415 2426 2437 2448
    2459 2470 2481 2492 2503 2514 2516 2527 2538 2549
    2560 2571 2582 2593 2604 2615 2617 2628 2639 2650
    2661 2672 2683 2694 2705 2716 2718 2729 2740 2751
    2762 2773 2784 2795 2806 2817 2819 2830 2841 2852
    2863 2874 2885 2896 2907 2918 2920 2931 2942 2953
    2964 2975 2986 2997 3008 3023 3034 3045 3056 3067
    3078 3089 3100 3111 3113 3124 3135 3146 3157 3168
    3179 3190 3201 3212 3214 3225 3236 3247 3258 3269
    3280 3291 3302 3313 3315 3326 3337 3348 3359 3370
    3381 3392 3403 3414 3416 3427 3438 3449 3460 3471
    3482 3493 3504 3515 3517 3528 3539 3550 3561 3572
    3583 3594 3605 3616 3618 3629 3640 3651 3662 3673
    3684 3695 3706 3717 3719 3730 3741 3752 3763 3774
    3785 3796 3807 3818 3820 3831 3842 3853 3864 3875
    3886 3897 3908 3919 3921 3932 3943 3954 3965 3976
    3987 3998 4009 4024 4035 4046 4057 4068 4079 4090
    4101 4112 4114 4125 4136 4147 4158 4169 4180 4191
    4202 4213 4215 4226 4237 4248 4259 4270 4281 4292
    4303 4314 4316 4327 4338 4349 4360 4371 4382 4393
    4404 4415 4417 4428 4439 4450 4461 4472 4483 4494
    4505 4516 4518 4529 4540 4551 4562 4573 4584 4595
    4606 4617 4619 4630 4641 4652 4663 4674 4685 4696
    4707 4718 4720 4731 4742 4753 4764 4775 4786 4797
    4808 4819 4821 4832 4843 4854 4865 4876 4887 4898
    4909 4920 4922 4933 4944 4955 4966 4977 4988 4999
    Sum of Self-number : 3586573

    맞나요..? 제법 크군요..
  3. 2009/10/06 11:46
    댓글 주소 수정/삭제 댓글
    #include <stdio.h>
    #include <stdlib.h>

    unsigned char number[5001];

    int self_generator(int num);

    int main()
    {
    int i, temp, sum;

    for (i=1; i<5001; i++) number[i] = 0;
    printf("\nSelf-number : ";);

    for (i=1; i<5001; i++) {
    temp = self_generator(i);
    if (temp < 5001) number[temp] = 1;
    }

    for (i=1; i<5001; i++) {
    if (!number[i]) {
    printf("%d ", i);
    sum += i;
    }
    }

    printf("\nSum of Self-number : %d ", sum);

    getch();
    }

    int self_generator(int num)
    {
    int temp[4], ret_val;

    temp[3] = num;

    temp[0] = temp[3]/1000;
    temp[3] %= 1000;
    temp[1] = temp[3]/100;
    temp[3] %= 100;
    temp[2] = temp[3]/10;
    temp[3] %= 10;

    ret_val = temp[0]+ temp[1]+ temp[2]+ temp[3]+ num;

    return ret_val;
    }


BLOG main image
Cr4cK th3 W0Rld by 후니 유

1,213,886


Today : 100
Yesterday : 206
hit counters

카테고리

전체보기 (802)
Etc (246)
Hacked Brain (280)
My Project (32)
데일리 (22)
운영체제 (31)
프로그래밍 (92)
Securities (27)