Torry Puzzle (Basic type)---Waterloo Cup

Source: Internet
Author: User
Problem Description Torry Love maths since 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 froze and couldn't answer for a moment. So Torry turned to you who programmed you to work out the product of the first n prime numbers. However, given that you are only in touch with programming soon, Torry as long as you work out the value of 50000 on this number model. Input Format contains only a positive integer n, where n<=100000. output Format outputs a row, the value of the product modulo 50000 of the first n primes. Sample Input 1 Sample Output

2


Analysis of Problem solving:

the point here is to figure out how to deal with how to find primes.

The processing I do here is to find prime numbers from small to large.


Code:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace Std;
int main ()
{
int n, I, j, count = 0;
Long long sum = 1;
CIN >> N;
for (i = 2; I <= sqrt (10000); i++)
{
for (j = 2; J <i; j + +)
{
if (i% j = 0)
Break
}
if (J >= i)
{
count++;
sum = (sum * i)% 50000;
if (count = N)
Break
}
}
cout<<sum<<endl;
return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.