Problem Description
Torry Love maths from childhood. One day, the teacher told him, like 2, 3, 5, 7 ... Such numbers are called prime numbers. Torry suddenly thought of a problem, the first 10, 100, 1000, 10000 ... What is the product of a prime number? He told the teacher the question. The teacher was stunned and couldn't answer it. So Torry turned to the programmer, and asked you to calculate the product of the first n prime numbers. However, considering that you are only in touch with programming soon, Torry as long as you figure out the value of 50000 on the modulo.
Input Format
contains only a positive integer n, where n<=100000.
output FormatThe
output line, which is the value of the product modulo 50000 of the first n prime numbers.
Sample Input
1
Sample Output
2
Problem Solving Analysis:
The point here is to figure out how to deal with how to find prime numbers.
Here I do the processing is from small to large to find prime.
Code:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace Std;
int main ()
{
int n, I, j, count = 0, sum = 1;
CIN >> N;
The processing here is the key, first to prevent timeouts, first open square
Guaranteed time, the second is the use of the method of calculating primes,
The general number of the prime is and smaller than their own mold
A judgment is added here, if it can be done and is itself,
So is the prime number.
for (i = 2; I <= sqrt (10000); i++)
{
for (j = 2; J <i; j + +)
{
if (i% j = 0)
break;
}
if (J >= i)
{
count++;
sum *= i;
if (count = = N)
break;
}
}
C out<<sum%50000<<endl;
return 0;
}
Torry Puzzle (Basic type)---blue Bridge cup