1、递归实现辗转相除
ublic class Main {
public static int gcd(int a,int b){
if(a==0) return b;
return gcd(b%a, a);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner=new Scanner(System.in);
int a=scanner.nextInt();
int b=scanner.nextInt();
System.out.println(gcd(a,b));
}
}
2、筛法查找第n个素数(2为第0个)
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
int n=1000*1000*10;
int x=100001;
byte a[]=new byte[n];
for(int i=2;i<n/2;i++){
if(a[i]==1)
continue;
for(int k=2;k<n/i;k++){
if(i*k<n) a[i*k]=1;
}
}
int m=0;
for(int i=2;i<n;i++){
if(a[i]==0){
m++;
if(m==x)
System.out.println(i);
}
}
}
}