1.If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Find the sum of all the multiples of 3 or 5 below 100 (计算1000以内能被3或5整除的数之和) #include <iostream> using namespace std; i…
Product-sum numbers A natural number, N, that can be written as the sum and product of a given set of at least two natural numbers, {a1, a2, … , ak} is called a product-sum number: N = a1 + a2 + … + ak = a1 × a2 × … × ak. For example, 6 = 1 + 2 + 3 =…
Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. The code resemble : import math limit = 2000000 crosslimit = int(math.sqrt(limit)) #sieve = [False] * limit sieve =…
对每个数字分解素因子,最后对每个素因子去其最大的指数,然后把不同素因子的最大指数次幂相乘,得到的就是最小公倍数 python不熟练,代码比较挫 mp = {} def process(n): i = 2 while i*i <= n: cnt = 0 if n%i == 0: while n%i == 0: cnt += 1 n /= i if i in mp: mp[i] = max(mp[i], cnt) else: mp[i] = cnt i += 1 if n > 1: if n in…
题目的大意很简单 做法的话. 我们就枚举1~10000的数的立方, 然后把这个立方中的有序重新排列,生成一个字符串s, 然后对于那些符合题目要求的肯定是生成同一个字符串的. 然后就可以用map来搞了 这里偷懒用了python import string dic = {} def getstr(n): sn = str(n) arr = [] for c in sn: arr.append(c) arr.sort() return ''.join(arr) for i in xrange(1, 1…