"Problem: To print in ascending order all primes less than 10000. Use an array of processes, SIEVE, in which each process inputs a prime from its predecessor and prints it. The process then inputs an ascending stream of numbers from its predecessor a…
本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable numbers Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a ≠ b…
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("完数有…
//函数fun功能:求n(n<10000)以内的所有四叶玫瑰数并逐个存放到result所指数组中,个数作为返回值.如果一个4位整数等于其各个位数字的4次方之和,则称该数为函数返回值. #include<stdio.h> #pragma warning (disable:4996) int fun(int n, int result[]) { ,j=; int a, b, c, d; ; i < n; i++) { a = i / ; b = (i % ) / ; c = (i %…
#求10万以内所有素数 num = int(input(">>>")) strs = '' for i in range(2,num): for c in range(2,int(i**0.5)+1): if i%c == 0: break else: strs += str(i)+' ' print(strs) 方法2: print(2) for i in range(3,100001,2): if i>10 and i%10 == 5: continue e…
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…
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? 译文: 观察第一组质数可知,第6位质数为13,那么第10001位质数是多少呢? ============================ 第一次code: import java.util.ArrayList; import j…
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 第六天_流程语句 { class Program { static void Main(string[] args) { //找出100以内的所有质数,质数只能被1和它本身整除的数,质数从2开始. 7 7%2 ,7%3 , 7%4 , 7%5, 7…
题目:我年龄的立方是个4位数.我年龄的4次方是个6位数.这10个数字正好包含了从0到9这10个数字,每个都恰好出现1次,求出我今年几岁. 直接拷贝运行就可以了. public class Age { public static void main(String[] args) { // TODO Auto-generated method stub Age a = new Age(); a.fun(); } private int fun(){ for(int i = 0;i<60;i++){…
首先得求出能整除A的数,再判断I是否是质数!!! import java.util.*; public class aa { public static void main(String[] args) { System.out.println("Please input the number:"); Scanner in=new Scanner(System.in); int a; a=in.nextInt(); if(a==1||a==0) System.out.println(&…