• <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++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            找出回文素數

            Posted on 2012-09-22 17:45 hoshelly 閱讀(332) 評論(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) //將數字轉換為字符串
            {
                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;//取本次數字的最高位
                str[i++] = c+48;
                a = a%d; //取余數
                h--;
                }
                str[i]='\0'; //最后末尾加字符串結束符
            }

            int Is_Pal(int b)
            {
                int len = diglen(b);
                int ok = 1,j;
                char* str = (char*)malloc(sizeof(char)*(len+1));
                IntoStr(b,str); //將數字轉換為字符數組,也可以用itoa函數或 sprintf函數
                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;
            }
            久久无码精品一区二区三区| 97久久精品人人澡人人爽| 岛国搬运www久久| 麻豆久久| 久久精品99久久香蕉国产色戒 | 国产呻吟久久久久久久92| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 精品久久久久久成人AV| 久久er99热精品一区二区| 欧美激情精品久久久久| 精品久久久无码21p发布 | 国产精品久久久久久久久鸭 | 久久青青色综合| 91精品国产91久久久久久青草| 久久99热这里只有精品66| 国产国产成人精品久久| 久久99国产综合精品| 777午夜精品久久av蜜臀| 亚洲欧洲久久久精品| 国产免费福利体检区久久| 精品精品国产自在久久高清| 亚洲中文字幕无码久久2020 | 欧美精品丝袜久久久中文字幕| 久久免费线看线看| 岛国搬运www久久| 久久午夜福利电影| 欧美日韩精品久久免费| 综合人妻久久一区二区精品| 久久SE精品一区二区| 久久国产精品99精品国产987| 久久99久久成人免费播放| 狠狠色婷婷久久综合频道日韩| 色88久久久久高潮综合影院| 国产亚洲综合久久系列| 国内精品久久久久久久久电影网| 伊人久久综合热线大杳蕉下载| 精品多毛少妇人妻AV免费久久| 国产69精品久久久久久人妻精品 | 日韩精品久久无码人妻中文字幕 | 婷婷久久综合九色综合九七| 亚洲国产精品综合久久网络|