Problem 37</h2>
14 February 2003</div>
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3.
Find the sum of the only eleven primes that are both truncatable from left to right and right to left.
NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.</p>
</div>
</div>
Answer:</div></td>
748317</b></td>
</tr>
</tbody>
</table>
#include
using namespace std;
bool isprime(int n)
{
int i=0;
if(n==2||n==3||n==5||n==7)return true;
else if(n==1||n%2==0)return false;
for(i=3;i*i<=n;i+=2)
if(n%i==0)return false;
return true;
}
int digits(int n)
{
int dig=0;
for(;n>=1;n/=10)
dig++;
return dig;
}
bool travels(int n)
{
int j,i,tmp=n,k=digits(n);
for(j=0;j
{
if(!isprime(tmp))
return false;
tmp/=10;
}
for(j=k;j>1;j--)
{
for(tmp=1,i=0;i
tmp*=10;
n%=tmp;
if(!isprime(n))
return false;
}
return true;
}
int main (int argc, char const* argv[]) {
int n=0,i,sum=0;
for(i=11;;i+=2)
{
if(travels(i))
{
n++;
sum+=i;
if(n==11)
break;
}
}
cout<
return 0;
}
分析预测模型在机器学习中的应用之线性回归
回归能做任何事情 Continue reading
android中的线程与进程模型
Published on June 15, 2016
android内存优化之图片加载
Published on June 11, 2016
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3.
Find the sum of the only eleven primes that are both truncatable from left to right and right to left.
NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.</p>
</div>
</div>
|
Answer:</div></td>
748317</b></td> | </tr> </tbody> </table> #include using namespace std; bool isprime(int n) bool travels(int n) 分析预测模型在机器学习中的应用之线性回归回归能做任何事情 Continue reading android中的线程与进程模型Published on June 15, 2016android内存优化之图片加载Published on June 11, 2016 |