1501131824-blue bridge cup-algorithm training Torry confusions (basic type)
Algorithm training Torry confusion (basic type) Time Limit: 1.0 s memory limit: 512.0 MBProblem description Torry loves mathematics from an early age. One day, the teacher told him, like 2, 3, 5, 7 ...... Such a number is called a prime number. Torry suddenly came up with a question: the first 10, 100, 1000, 10000 ...... What is the product of prime numbers? He told the teacher about the problem. The teacher was stunned and could not answer the question at the moment. So Torry turned to someone who could program it. Please calculate the product of the First n prime numbers. However, considering that you are not familiar with programming, Torry only needs to calculate the value of 50000 on this digital model. The input format only contains a positive integer n, where n <= 100000. The output format outputs a row, that is, the product modulo of the first n prime numbers is 50000. Sample input 1 sample output 2 solution ideas because I don't know the number of 100,000th prime numbers, I can end with a large number of n, calculate the zero-n prime number in the table, and then start from 0 to determine if it is a prime number, multiply and j ++. You can enter 100000 to determine which number is reached, then modify the n of the program. Note that answer requires 64-bit int type. This topic also examines the same theorem. C code
# Include
# Include
Int a [11000000], B [110000]; int main () {int n; int I, j, k ;__ int64 answer; scanf ("% d ", & n); memset (a, 0, sizeof (a); a [0] = a [1] = 1; for (I = 0; I <10000000; I ++) {if (a [I]) continue; for (j = I + I; j <10000000; j + = I) a [j] = 1 ;} answer = 1; for (I = 0, j = 0; I <10000000 & j
JAVA code
Confusions of package torry; import java. util. extends; public class Main {public static void main (String [] args) {extends input = new loads (System. in); int [] a = new int [1100000]; int [] B = new int [110000]; int n = input. nextInt (); int I, j, k; long answer; a [0] = a [1] = 1; for (I = 0; I <1000000; I ++) {if (a [I] = 1) continue; for (j = I + I; j <1000000; j + = I) a [j] = 1 ;} answer = 1; for (I = 0, j = 0; I <1000000 & j