• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天之道

            享受編程的樂趣。
            posts - 118, comments - 7, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            找出回文素數(shù)

            Posted on 2012-09-22 17:45 hoshelly 閱讀(324) 評論(0)  編輯 收藏 引用 所屬分類: Programming

            The number 151 is a prime palindrome because it is both a prime number and a palindrome (it is the same number when read forward as backward). Write a program that finds all prime palindromes in the range of two supplied numbers a and b (5 <= a < b <= 1000,000,000); both a and b are considered to be within the range .
            Input
            Line 1: Two integers, a and b
            Output
            The list of palindromic primes in numerical order, one per line.
            Sample Input
            5 500
            Sample Output
            5
            7
            11
            101
            131
            151
            181
            191
            313
            353
            373
            383


            #include<stdio.h>
            #include<math.h>
            #include<stdlib.h>
            int i;
            int Is_Prime(int a)
            {
                double t = a;
                for(i=2;i<=sqrt(t);i++)
                {
                    if(a % i == 0)
                        return 0;
                }
                    return 1;
            }
            int diglen(int c)
            {
                if(c/10 == 0)
                    return 1;
                int count=0;
                while(c)
                {
                    c=c/10;
                    count++;
                }
                return count;
            }

            void IntoStr(int a,char* str) //將數(shù)字轉(zhuǎn)換為字符串
            {
                int h= diglen(a)-1,i=0;
                while(h+1)
                {
                int k,c,d=1;
                for(k=0;k<h;k++)
                {
                    d=d*10;
                }

                c=a/d;//取本次數(shù)字的最高位
                str[i++] = c+48;
                a = a%d; //取余數(shù)
                h--;
                }
                str[i]='\0'; //最后末尾加字符串結(jié)束符
            }

            int Is_Pal(int b)
            {
                int len = diglen(b);
                int ok = 1,j;
                char* str = (char*)malloc(sizeof(char)*(len+1));
                IntoStr(b,str); //將數(shù)字轉(zhuǎn)換為字符數(shù)組,也可以用itoa函數(shù)或 sprintf函數(shù)
                for(i=0,j=len-1;i < len/2;i++,j--)
                {
                    if(str[i] != str[j])
                        ok = 0;
                    
                }
                free(str);
                if(ok == 1)
                    return 1;
                else
                    return 0;
            }

            int main()
            {
                int a,b,j;
                scanf("%d%d",&a,&b);
                for(j=a;j<=b;j++)
                {
                    if(Is_Prime(j) && Is_Pal(j))
                        printf("%d\n",j);
                }
                return 0;
            }
            亚洲中文久久精品无码ww16| 久久精品国内一区二区三区| 久久精品无码专区免费| 久久久黄片| 亚洲中文字幕无码久久2020| 久久99免费视频| 久久99久久无码毛片一区二区 | 久久av免费天堂小草播放| 久久一本综合| 99久久免费国产特黄| 天天影视色香欲综合久久| 久久棈精品久久久久久噜噜| 欧美激情精品久久久久久久九九九| 亚洲色大成网站WWW久久九九| 久久免费国产精品一区二区| 久久大香萑太香蕉av| 亚洲一本综合久久| 久久久SS麻豆欧美国产日韩| 99热热久久这里只有精品68| 亚洲av日韩精品久久久久久a| 91麻精品国产91久久久久| 中文国产成人精品久久不卡| 久久最新免费视频| 久久久久香蕉视频| 国产精品伦理久久久久久| 国产精品久久久久久| 久久久噜噜噜久久熟女AA片| 99久久综合国产精品免费| 亚洲国产精品综合久久一线| 精品国产福利久久久| www久久久天天com| 久久国产高潮流白浆免费观看| 久久久精品国产免大香伊 | 伊人久久久AV老熟妇色| 中文字幕精品久久久久人妻| 午夜视频久久久久一区| 久久亚洲国产成人影院网站| 久久久久亚洲AV成人网| 亚洲日本va午夜中文字幕久久 | 国产精品久久久久久久久免费| 99久久久精品免费观看国产|