Description-Problem description
One day, the male Pa taught himself the first style of the law of the Winds: the shadows ... Footwork (Disciple one: Lord of the Church, you are panting.) Wind: You shut up. The key to the Chase is breathing (it's not good to breathe ...) )。
Using the trick is not every step of the pant, but in a specific number of steps panting. In general, the higher the skill, the more sparse the pant. The number of steps to pant matches a specific rule: first if Sushu (disciple two: Wow!) Lord, you will still be the birds of the bird, I worship you well! But what does Sushu mean? Wind: Stupid, that's Hanyu Pinyin! Second if a palindrome number, palindrome number is the same number of positive and negative, such as: 123321,121,5211314 (disciple three: Church owner, the last one seems not ...) Wind: Nonsense, of course not, I am to examine your error-correcting ability! Now give two numbers m,n (5< =m< n< =100,000,000), and you need to figure out what steps you need to breathe between m,n. (including M,n). The calculated can be promoted to a disciple of the church, monthly salary (1000000000000000000000000000000000000000000 MOD 10) yuan.
Perhaps in the Ben of God, this is a water can not water, but I think it is necessary to mention. First of all, this is a judge of the number of primes + palindrome numbers, for palindrome number, the definition of Baidu is as follows:
"Palindrome" is to read the anti-reading can read through the sentence, it is all the time and time there is a rhetorical way and word game, such as "I for everyone, everyone for me" and so on. In mathematics there is such a characteristic of such a number that it becomes a palindrome number (palindrome numbers). Set N is an arbitrary natural number. If the numbers of n are reversed and the natural number N1 is equal to N, then N is a palindrome number. For example, if n=1234321, then n is a palindrome number, but if n=1234567, then n is not a palindrome number. In addition, he gives the C + + judgment code as follows:
1#include <iostream>2 using namespacestd;3 BOOLSymmLongm)4 {5 Longtemp = m,n=0;6 while(temp)7 {8N. = nTen+temp%Ten;9temp = temp/Ten;Ten } One return(M = =n); A } - intMainintARGC, _tchar*argv[]) - { the Longm; -cout<<"Please enter an integer:"; -Cin>>m; -cout<<"entered the"<<symm (m) <<"a palindrome number! "; + return 0; -}
In the opinion of the individual, the method of judging the palindrome number is basically used. But you can also read a string, use S.size () to determine whether it is odd or even, then search from left to right.
My Code:
1#include <iostream>2#include <cmath>3 using namespacestd;4 Const intmaxn=3000000;5 //int P[MAXN];6 intM,n;7 //int sum=0;8 //void make ()9 //{Ten //p[1]=1; One //for (int i=2;i<=sqrt (MAXN); i++) A //if (p[i]==0) - //for (int j=2;j<=sqrt (MAXN)/i;j++) - //p[i*j]=1; the //} - BOOLPd_1 (intm) - { - inttemp=m,n=0; + while(temp) - { +n=n*Ten+temp%Ten; ATemp/=Ten; at } - return(m==n); - } - //bool Pd_2 (int m) - //{ - //if (p[m]) in //return false; - //Else to //return true; + //} - BOOLPd_2 (intm) the { * for(intI=2; i<=sqrt (m); i++) $ {Panax Notoginseng if(m%i==0) - return false; the } + return true; A } the BOOLPd_3 (intm) + { - intk=m%Ten; $ if((k==2|| k==4|| k==5|| k==6|| k==8|| k==0) && (m/Ten>=1)) $ return false; - Else - return true; the } - intMain ()Wuyi { the //Make (); -Cin>>m>>N; Wu if(n>10000000) -n=10000000; About for(inti=m;i<=n;i++) $ { - if(Pd_1 (i) &&pd_3 (i)) - if(Pd_2 (i)) -cout<<i<<Endl; A } + return 0; the } - /************************************************************** $ problem:1109 the User:lwq the language:c++ the result:accepted the time:559 Ms - memory:1320 KB in ****************************************************************/
A little view of yzoi1109&&viojs1042 minimum steps--palindrome number