Nine degrees oj--1163 (c + +)

Source: Internet
Author: User

#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 how many eligible primes are in the 1~n, in fact only 0 and not 0 difference

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 criterion is k<sqrt ((double) i), the result is incorrect

Once except to prove that I is not a prime, I can be judged next
if (i%k = = 0) {
Flag = 0;
Break
}
If not done, continue the loop
else {
flag = 1;
Continue
}
}

if (flag = = 0) {//I is not a prime number
Continue
}
else {//I is a prime number
if (i%10 = = 1) {//I's bits are 1
Vec.push_back (i);
num = num + 1;
Continue
}
else {//i bits are 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;

}

Nine degrees oj--1163 (c + +)

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.