9 degrees OJ--1163 (C ++), 9 degrees oj -- 1163

Source: Internet
Author: User

9 degrees OJ--1163 (C ++), 9 degrees oj -- 1163

# Include <iostream>
# Include <vector>

Using namespace std;

Int main (){

Int n;

While (cin> n ){

Vector <int> vec;

Int num = 0; // num is used to record 1 ~ The number of required prime numbers in n is actually the difference between 0 and 0.

For (int I = 11; I <n; I ++ ){

Int flag = 0; // flag is intended to determine whether an integer I is a prime number. If it is a prime number, flag = 1; otherwise, flag = 0

For (int k = 2; k <I/2 + 1; k ++) {// if the condition is k <sqrt (double) I), the result is incorrect.

// Once the Division proves that I is not a prime number, you can determine the next I.
If (I % k = 0 ){
Flag = 0;
Break;
}
// Continue the loop if not exhausted
Else {
Flag = 1;
Continue;
}
}

If (flag = 0) {// I is not a prime number
Continue;
}
Else {// I is a prime number
If (I % 10 = 1) {// the bit of I is 1
Vec. push_back (I );
Num = num + 1;
Continue;
}
Else {// I is not 1
Continue;
}
}
}

If (num = 0 ){
Cout <"-1" <endl;
}
Else {
For (int m = 0; m <vec. size ()-1; m ++ ){
Cout <vec [m] <"";
}
Cout <vec [vec. size ()-1] <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.