• <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;
            }
            久久久久99这里有精品10 | 久久九九兔免费精品6| 久久亚洲国产成人影院| 久久久无码精品亚洲日韩京东传媒| 狠狠色丁香久久婷婷综合_中| 久久国产一区二区| 久久成人精品| 无码人妻久久一区二区三区免费| 人妻少妇久久中文字幕一区二区| 91精品国产高清久久久久久国产嫩草 | 成人综合伊人五月婷久久| 久久国产精品免费| 99久久精品免费看国产一区二区三区 | 久久综合色老色| 99久久亚洲综合精品成人| 久久久久香蕉视频| 国产美女久久久| 久久九九兔免费精品6| 欧美日韩中文字幕久久久不卡| 99国产欧美久久久精品蜜芽| 久久笫一福利免费导航 | 国产精品久久久久jk制服| 久久综合色老色| 久久综合成人网| 久久99精品国产麻豆婷婷| 久久久无码人妻精品无码| 久久综合给合久久狠狠狠97色69| 久久人人爽人人爽人人片AV麻豆| 精品免费久久久久久久| 人妻少妇久久中文字幕一区二区 | 久久久久久精品免费看SSS| 国内精品久久久久久久影视麻豆| 久久国产精品成人片免费| 久久综合久久自在自线精品自| 亚洲伊人久久成综合人影院| 久久AⅤ人妻少妇嫩草影院| 99久久综合狠狠综合久久止| 国产人久久人人人人爽| 97久久超碰国产精品旧版 | 亚洲?V乱码久久精品蜜桃| 久久久久久久综合综合狠狠|