1501131824-blue bridge cup-algorithm training Torry confusions (basic type)

Source: Internet
Author: User

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
     
      

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.