Develop
2016.09.09 11:16
[c] 셀프 넘버(Self Number) 구하기
조회 수 2258 댓글 1
어떤 자연수 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 보다 작은 모든 셀프 넘버들의 합을 구하라.
# Self Number.
#include <stdio.h> int main(){ int a, b, c, d, res, sum=0; int p[5000] = {0,}; for(int num=1; num<5000; num++){ //find self number a = num / 1000; b = (num / 100) % 10; c = (num / 10) % 10; d = num % 10; res = a + b + c + d + num; if(res < 5000){ p[res] = 1; } //make sum if(p[num] == 0){ printf("%3d ", num); sum += num; } } printf("\nThe sum is %d\n", sum); return 0; }
TAG •
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1113 | Develop | 리팩토링 계획안 | hooni | 2017.05.15 | 746 |
1112 | Develop | [Android Error] The number of method references in a .dex file cannot exceed 64K | hooni | 2016.11.10 | 752 |
1111 | Develop | [linux] CentOS Apache 웹서버에 HTTPS 적용 | hooni | 2015.10.23 | 781 |
1110 | System/OS | [macos] How to Fix ‘You Shut Down Your Computer Because of a Problem’ | hooni | 2022.06.01 | 784 |
1109 | Develop | [io] Apple Watch, Today Extension 앱ID 설정 | hooni | 2016.04.20 | 792 |
1108 | Algorithm | OCB5 Injection 앗싸뵹! ㅋㅋ | hooni | 2014.07.01 | 796 |
1107 | System/OS | [linux] The Ultimate Wget Download Guide With 15 Awesome Examples | hooni | 2020.05.26 | 797 |
1106 | Develop | [c] 기막힌 정렬 코드 ㅋㄷ | hooni | 2015.10.13 | 805 |
1105 | Develop | [android] 초간단 얼럿 (AlertDialog) | hooni | 2016.10.21 | 807 |
1104 | Etc | 사이버보안실무 수업 메모 | hooni | 2017.03.30 | 807 |
1103 | Develop | [js] e.stopPropagation() VS e.preventDefault () | hooni | 2015.04.14 | 808 |
1102 | Database | [mysql] MySQL 백업 및 복구 | hooni | 2019.11.22 | 817 |