Usaco--1.5prime palindromes

Source: Internet
Author: User

A property: The palindrome number of even digits is a multiple of 11 (except for 11 itself), so even if the bit is not considered, then we will construct the palindrome number of odd digits, and then judge whether this number is a prime line.

The code is as follows:

/*id:15674811lang:c++task:pprime*/#include <iostream>#include <cstdio>#include <cstring>#include <fstream>#include <cmath>using namespace STD;BOOLIs_prime (intN) {intk=sqrt(n) +0.5; for(intI=2; i<=k;i++)if(n%i==0)return 0;return 1;}/// structure to get the odd number of palindrome number within 10000000intGet (int*B) {intCnt=0;palindrome number of///1 bit        for(intI=1; i<=9; i++) b[cnt++]=i; b[cnt++]= One;/// even number of palindrome number is a multiple of 11, so do not consider        palindrome number of///3 bit         for(intI=1; i<=9; i++) for(intj=0; j<=9; j + +) {intd=i* -+j*Ten+i;            B[cnt++]=d; }palindrome number of///5 bit          for(intI=1; i<=9; i++) for(intj=0; j<=9; j + +) for(intk=0; k<=9; k++) {intD=10000*i+ +*j+ -*k+Ten*j+i;                 B[cnt++]=d; }palindrome number of///7 bit          for(intI=1; i<=9; i++) for(intj=0; j<=9; j + +) for(intk=0; k<=9; k++) for(intD=0;d <=9;d + +) {intd1=1000000*i+100000*j+10000*k+ +*d+ -*k+Ten*j+i;                  B[CNT++]=D1; }returnCNT;}intMain () {intb1[20000]; Ofstreamcout("Pprime.out"); IfstreamCin("Pprime.in");intCnt=get (B1);intb; while(Cin&GT;&GT;A&GT;&GT;B) { for(intI=0; i<cnt;i++)if(B1[i]>=a&&b1[i]<=b&&is_prime (B1[i]))cout<<b1[i]<<endl;Else if(B1[I]&GT;B) Break; }return 0;}

Usaco--1.5prime palindromes

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.