1-100中的有趣数,和特殊回文数,水仙花数。
2条回答 默认 最新
- Yangyufan95 2021-12-19 10:52关注
public static void main(String[] args) { int x = 0; for (int i = 0; i < 2021; i++) { int n = i; for (int j = 1; j <= Math.sqrt(n); j++) { if((int)Math.pow(j, 2)+(int)Math.pow((int)Math.sqrt(n-(int)Math.pow(j, 2)), 2)==n &&j>=(int)Math.sqrt(n-(int)Math.pow(j, 2))){ // System.out.println(j+" "+(int)Math.sqrt(n-(int)Math.pow(j, 2))); x++; //有的数有多种表示方法,例如 25 = 5 * 5 + 0 * 0 = 3 * 3 + 4 * 4,在算答案时只算一次,所以跳出本次循环 break; } } } System.out.println("在 1 到 2021 中有多少"+x+"个这样的数:"); }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥20 西门子S7-Graph,S7-300
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效
- ¥15 悬赏!微信开发者工具报错,求帮改