【python】求水仙数】的更多相关文章

for i in range(100, 1000): sum = 0 temp = i while temp: sum = sum + (temp%10) ** 3 temp //= 10 # 注意使用地板除哦~ if sum == i: print(i) 来源:小甲鱼习题…
水仙花数是指一个n位数(n>=3),它每一个位上数字的n次幂之和等于它本身,n为它的位数.(比如:1^3+5^3+3^3 = 153) 水仙花数又称阿姆斯特朗数. 三位的水仙花数有4个:153,370,371,407 四位的水仙花数有3个:1634,8208,9474 五位的水仙花数有3个:54748,92727,93084 六位的水仙花数有1个:548834 七位的水仙花数有4个:1741725,4210818,9800817,9926315 八位的水仙花数有3个:24678050,24678…
所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身. 例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方 public class R2 { public static void main(String[] args) { /* 二.求水仙花 水仙花打印出100-999之间所有的"水仙花数" 所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身. 例如:153是一个"水仙…
前文链接:帮初学者改代码——playerc之“练习:求完数问题”(上) 再来看看be_ferfect()应该如何改. be_ferfect()函数的功能是判断number是否为完数,同时把因子对写入divisers数组.以28这个完数为例,在数组中将依次写入 1 28 2 14 4 7 输出时则按要求依大小次序输出 1 2 4 7 14.先从前跳到后,到头之后掉头,再从后跳到前. 这种写入的方式决定了输出代码写起来要困难一些.如果希望输出写得容易些的话,写入时就必须改变这种图省事的办法. 有很多…
原文:“练习:求完数问题” 原代码: // #include <stdio.h> #include <stdlib.h> #include <math.h> #define DIVISERS_MAX_LENGTH (1024) #define TOP (10000) int main(void) { /* * 储存因子,成对的储存.例如6 * 1,6, 2,3 */ int divisers[DIVISERS_MAX_LENGTH] = {0}; int diviser…
// GetWanShu.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "omp.h" #include <Windows.h> #include "time.h" //函数声明 void getWanShuBySection(); void getWanShu(); void getWanShuByReduction(); int _tmain(int argc, _TCH…
使用python求字符串或文件的MD5 五月 21st, 2008 #以下可在python3000运行. #字符串md5,用你的字符串代替'字符串'中的内容. import hashlib md5=hashlib.md5('字符串'.encode('utf-8′)).hexdigest() print(md5) #求文件md5 import hashlib #文件位置中的路径,请用双反斜杠, 如'D:\\abc\\www\\b.msi' file='[文件位置]' md5file=open(fi…
内容: 求两数的整数商 和 商 ,商保留两位小数 输入说明: 一行 两个整数 输出说明: 一行,一个整数,一个实数(两位小数) 输入样例:   12 8 输出样例 : 1 1.50 #include <stdio.h> int main(void) { ; ; scanf("%f %f", &num1, &num2); printf("%d %.2f", (int)(num1 / num2), num1 / num2); ; } 或者 #…
内容: 求两数的整数商 和 余数 输入说明: 一行两个整数 输出说明: 一行两个整数 输入样例:   18 4 输出样例 : 4 2 #include <stdio.h> int main(void) { ; ; scanf("%d %d", &num1, &num2); printf("%d %d", num1 / num2, num1 % num2); ; }…
Under Attack II Time Limit: 5 Seconds      Memory Limit: 65536 KB Because of the sucessfully calculation in Under Attack I, Doctor is awarded with Courage Cross and promoted to lieutenant. But the war seems to end in never, now Doctor has a new order…