A Smith number is a composite number whose digit sum is equal to the digit sum of its prime factorization, counted with multiplicity.
For example, 85 is a Smith number:
85 = 5 × 17- Digit sum of
85:8 + 5 = 13 - Digit sum of prime factors:
5 + 1 + 7 = 13
Prime numbers are not Smith numbers, even when their own digit sum matches the digit sum of their trivial factorization.
- JDK 21 or newer
- Gradle 9.5.x or newer compatible with Kotlin 2.4.0
This project uses the Kotlin JVM Gradle plugin 2.4.0.
gradle runDefault output:
Smith numbers between 1 and 100:
4
22
27
58
85
94
gradle testsrc/main/kotlin/Main.kt # Smith number implementation and CLI entry point
src/test/kotlin/MainTest.kt # Unit tests for detection, factoring, and digit sums
MIT License
Copyright (c) 2023 Halil OZEL
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.