用python求从1开始第1000个质数? 质数:只能被1和它本身整除的数.那好,我们开始写程序(一个小算法). def calc_prime(prime,num): i,gab=7,2 while num>3: flag=True for x in prime: if x*x>i: break if i%x==0: flag=False break if flag: prime.append(i) if len(prime)>=num: break gab=6-gab i+=gab r
using System;namespace Loops{ class Program { static void Main(string[] args) { /*局部变量定义*/ int i, j; for (i = 2; i < 100; i++) { for (j = 2; j <= i / j; j++) if ((i % j) == 0) break;//如果找到,则不是质数 if (j > (i / j)) Console.WriteLine("{0} 是质数 /n
//这是求一个数的质因数,例如:12=2*2*3 其中2,3都是质数.function primeArray(n, array) { array = new Array(); for (var i = 2; i < n; i++) { //是否为质数 if (isPrime(i)) { var temp_R = n % i;//余数 var temp_c = n / i;//商 //是否整除 if (temp_R == 0) { // array[array.length] = i; array
代码 #include <bits/stdc++.h> #define rin(i,a,b) for(int i=(a);i<=(b);++i) #define irin(i,a,b) for(int i=(a);i>=(a);--i) #define trav(i,a) for(int i=head[(a)];i;i=e[i].nxt) typedef long long LL; using std::cin; using std::cout; using std::endl;
public class aa{ public static void main (String args []){ //author:qq986945193 for (int i = 100;i<201;i++){ boolean flag = true; for (int j = 2;j<i-1;j++){ if(i%j==0){ flag = false; } } if(flag){ System.out.println(i); } } } } java源代码下载地址:http://do
Description: Count the number of prime numbers less than a non-negative number, n click to show more hints. References: How Many Primes Are There? Sieve of Eratosthenes Credits:Special thanks to @mithmatt for adding this problem and creating all test