水仙花数的计算算法
发布日期:2021-04-30 21:05:53
浏览次数:96
分类:精选文章
本文共 1805 字,大约阅读时间需要 6 分钟。
?????????????????????????????n?????n?3??????????n??????????????????????????????????????????153?370?371?407?
?????????
????????????????????????
????????????n??????????10^(n-1)?10^n - 1???????????100?999?
??????????????????????????
????????????????????????
?????????????????n????????????
???????????????????????????????????
??????????????????
??????
??????????
long start = (long) Math.pow(10, n - 1);long end = (long) Math.pow(10, n) - 1;
??????
for (long i = start; i <= end; i++) { // ???????????? if (isWater???(i, n)) { System.out.println(i); }} ??????? ?????????????10???10???????????????????
while (num != 0) { temp = num % 10; sum += Math.pow(temp, n); num = num / 10; ?????? ????????????????????????
if (sum == num) { System.out.println("?????" + num);} ????
public class Water??? { public static void main(String[] args) { int n = 3; System.out.println("???????"); searchWaterSsus(n); System.out.println("???????"); n = 4; searchWaterSsus(n); System.out.println("???????"); n = 5; searchWaterSsus(n); } private static void searchWaterSsus(int n) { long start = (long) Math.pow(10, n - 1); long end = (long) Math.pow(10, n) - 1; for (long num = start; num <= end; num++) { long sum = 0; long temp = 0; // ?????????n???? do { temp = num % 10; sum += (long) Math.pow(temp, n); num /= 10; } while (num != 0); if (sum == num) { System.out.println(num); } } }} ????
????????????????????????
- ???????153, 370, 371, 407
- ???????1634, 8208, 9474
- ???????...
- ???????????????
???????????????????????????
发表评论
最新留言
路过按个爪印,很不错,赞一个!
[***.219.124.196]2026年06月08日 14时15分59秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
pip 或 pip3 为 Python 3 安装包?
2023-03-02
pip 无法从 requirements.txt 安装软件包
2023-03-02
pip/pip3更换国内源
2023-03-02
pip3 install PyQt5 --user 失败
2023-03-02
pip3命令全解析:Python3包管理工具的详细使用指南
2023-03-02
PIPE 接口信号列表
2023-03-02
pipeline配置与管理Job企业级实战
2023-03-02
pipeline项目配置实战
2023-03-02
Pipenv 与 Conda?
2023-03-02
QVGA/HVGA/WVGA/FWVGA分辨率屏含义及大小//Android虚拟机分辨率
2023-03-02
pipy国内镜像的网址
2023-03-02
quiver绘制python语言
2023-03-02
pip下载缓慢
2023-03-02
PIP使用SSH从BitBucket安装自定义软件包,无需输入SSH密码
2023-03-02
pip在安装模块时提示Read timed out
2023-03-02
pip更换源
2023-03-02