Solution: Create a linked list and use the sieve division method
For example, evaluate the prime number within 10
Linked List initialization: 2 3 4 5 6 7 8 9 10
After the first round of Filtering: 2 3 5 7 9
That is to say, remove 2 with the number next to 2,
After the second round of Screening: 2 3 5 7
That is, remove 3 with the number behind 3,
After the third
DescribeNow give you n number (0
Input
The first line gives the number of sets of test data represented by the integer M (0The first row of each set of test data gives you n, which represents the number of test data for that group.
The next n number is the data to be tested, with each number less than 1000
Output
Each set of test data results in a row, outputting all the
In some interview questions, there will also be questions about the so-called fixed number of digits. For example, here is a question:
In prime numbers less than 1000, which of the following two digits is 69?
Let's writeCodeSimple code:
Public Static VoidMain (string [] ARGs ){IntCounter = 0;For(IntI = 69; I ){If(Isprime (I) {counter++; System. Out. println
Test instructionsGive an n, how many successive primes and add up equals N.Ideas:Hit the prime list and then direct violence.Code:#include "cstdlib" #include "Cstdio" #include "CString" #include "Cmath" #include "queue" #include "algorithm" #include " iostream "#include" map "#include" stack "#include" vector "#define LL __int64#define inf-999999999999999999llusing namespace std; #define MAXN 10007bool M
Import java. util. arraylist;Import java. util. List;
Public class song {
/*** @ Param ARGs*/Public static void main (string [] ARGs ){// Todo auto-generated method stub/** 1. Calculate the first 10 divisible by 3 but not 7 within 100.**/Int COUNT = 0;For (int A = 0; A {If (a % 3 = 0 A % 7! = 0){COUNT = count + 1;System. Out. Print ("A =" + A + "\ t ");If (COUNT = 10 ){Break;}}}System. Out. println ();/** 2. Calculate all
Enter a description:
The input gives M and N in a row, separated by a space.
Output Description:
Outputs all prime numbers from PM to PN, 1 rows per 10 digits, separated by spaces, but no extra space at the end of the line.
Enter an example:
5 27
Output Example:
of
47 53 59 61 67 71 73 79 83 89
97 101 103
Import java.util.ArrayList;
Import java.util.List;
Import Java.util.Scanner;
A list can be used to store a range of data, but it takes up memory if the amount of data is large. So there is a way to generator in addition to ordinary functions. The flag statement is yield.Title Requirements:Write a generator, genprimes, that returns the sequence of prime numbers on successive calls to its next () Method:2, 3, 5 , 7, 11, ...Analysis:Here's h
How to print the Fibonacci series and prime number list
These are actually two very basic and simple questions. However, somehow often reminds me of these two problems, sometimes cake does not think of the solution and will be sweating ...................
Let's get down to the truth and paste the code for these two questions.
(1) print the Fibonacci series
// Java program for Fibonacci number using Loop.
Label: blog Io Java for 2014 problem on C log These are actually two very basic and simple questions. However, somehow often reminds me of these two problems, sometimes cake does not think of the solution and will be sweating ................... Let's get down to the truth and paste the code for these two questions. (1) print the Fibonacci series // Java program for Maid number using loop. public static int fibonacciloop (INT number) {If (number = 1 | Number = 2) {return 1;} int fibo1 =
Topic:
Phone List
Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 239 Accepted Submission (s): 96
Problem Descriptiongiven A list of phone numbers, determine if it is consistent in the sense this
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.