import java.util.Scanner;
import java.util.Random;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long seed=sc.nextLong();
int n=sc.nextInt();
Random random= new Random(seed);
double x,y=0;
long k=0,i=0;
for(i=0;i<n;i++){
int s;
if (i<1/n) {s=1;}
else {s=-1;}
x= random.nextDouble()*s; //產生隨機數
y= random.nextDouble()*s;
if(x*x+y*y<1) k++;
}
double pi=4*(double)k/(double)i;
System.out.println(pi);
sc.close();
}
}
以上代碼可以在eclipse中運行卻在PTA上顯示錯誤。因為我不了解如何產生-1到1之間的隨機數。