面试中,遇到一个题目:求解第N个素数. import java.util.Scanner; public class GetPrimeNumber { public static int NthPrime(int n){ int i = 2, j = 1; while (true) { j = j + 1; if (j > i / j) { n--; if (n == 0) break; j = 1; } if (i % j == 0) { i++; j = 1; } } return i; }
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
用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
给出N个正整数组成的数组A,求能否从中选出若干个,使他们的和为K.如果可以,输出:"YES",否则输出"NO".用Java实现 import java.util.Scanner; public class Main { public static void main(String[] args) { int num[] = new int[1000]; int N, K; Scanner scanner = new Scanner(System.in); N = s
//这是求一个数的质因数,例如: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
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA. Write a function to find all the 10-letter-long seq
public class ArrayDemo05 { public static void main(String[] args) { int list01[]={67,89,87,69,90,100,75,90}; int max; int min; max=min=list01[0]; for(int i=0;i<list01.length;i++){ if (list01[i]>max) max=list01