前n个质数的乘积

问题描述

 

Torry从小喜爱数学。一天,老师告诉他,像2、3、5、7……这样的数叫做质数。Torry突然想到一个问题,前10、100、1000、10000……个质数的乘积是多少呢?他把这个问题告诉老师。老师愣住了,一时回答不出来。于是Torry求助于会编程的你,请你算出

import java.util.Scanner;

public class ALGO51 {
 public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int count =0;
	int c =0;
	long num =1;
	while(count<n){
	      c++;
	      if(PanDuan(c)!=1){
	    	  num*=PanDuan(c); 
	    	  count++;
	      }
	}
	System.out.println(num%50000);
}
    public static long PanDuan(int d){
    	int c = 1;
    	for(int i=1;i*i<=d;i++){
    		if(d%i==0&&i!=1){
    			return c;
    		}
    	}
    	return d;
    }
}

。不过,考虑到你才接触编程不久,Torry只要你算出这个数模上50000的值。

 

输入格式

 

  仅包含一个正整数n,其中n<=100000。

 

输出格式

 

  输出一行,即前n个质数的乘积模50000的值。

 

样例输入

1

 

样例输出

2

猜你喜欢

转载自blog.csdn.net/qq_39536716/article/details/83041572
今日推荐