day12 --------------------------------------------------------------- 实例019:完数 题目 一个数如果恰好等于它的因子之和,这个数就称为"完数".例如6=1+2+3.编程找出1000以内的所有完数. 分析:如果能被a整除,那么a是因子,放入一个列表然后再求和,与原被除数相等,就是完数 1 for i in range(1,int(a)): 2 list = [] 3 if i >1: 4 for j in r
import java.util.ArrayList; import java.util.List; //一个数如果恰好等于它的因子之和,这个数就称为"完数".例如6=1+2+3.第二个完全数是28, //它有约数1.2.4.7.14.28,除去它本身28外,其余5个数相加, //编程找出1000以内的所有完数. public class Test { public static void main(String[] args) { System.out.print("完数有
a.b只要数字a能被数字b整除,不论b是不是质数,都算是a的因子.比如:8的质因子是 2, 2, 2,但8的因子就包括 1,2,4. import math for i in range(2, 1000): factors = [] #因子列表,i 每次循环都清空 for j in range(1, math.floor(i/2)+1): if i%j == 0: factors.append(j) if sum(factor
// 生成n个随机数,要求n个数的和等于100 function lessANumber(n, v) { var i, s = 0, r = [], x = v; for (i = 1; i < n; i++) { x = Math.random() * x; r.push(x.toFixed(0)); s += x; x = v - s; } r.push(x.toFixed(0)); return r; } function random(Min,Max){ var Range = Max
int getSum(int* arr, int len) { int sum = 0; for (int i = 0; i < len; ++i) { sum += arr[i]; } return sum; } void difPrint(int* arr, int len, vector<int> vct) { cout << vct.size() << " =m 数组: "; for (int i = 0; i < vct.siz
POJ1741:Tree Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 29574 Accepted: 9915 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v.
Given a non-negative integer c, your task is to decide whether there're two integers a and bsuch that a2 + b2 = c. Example 1: Input: 5 Output: True Explanation: 1 * 1 + 2 * 2 = 5 Example 2: Input: 3 Output: False Accepted 38,694 Submissions 117,992
1.输入1-127的ascii码并输出对应的字符 for i in range(1,128): print(chr(i)) 2.输入a,b,c,d,4个整数,计算a+b-c*d的结果 a = input("send integer num a is: ") b = input("send integer num b is: ") c = input("send integer num c is: ") d = input("sen