题解:UVA12802 Gift From the Gods
willAK
·
·
题解
题解:UVA12802 Gift From the Gods
题目大意
给定一个正整数 a,你需要输出它的两倍,即 2a。\
## 解题思路
每次先输出 $2a$,再判断 $a$ 是否是回文质数即可。
- 质数:因数只有 $1$ 和它本身得数。
- 回文数:正着和反着是一样的。
## 解题代码
```cpp
#include<bits/stdc++.h>
using namespace std;
int n;
bool ss(int n)//判断质数
{
if(n<2) return false;
else if(n==2) return true;
for(int i=2;i<n;i++)
{
if(n%i==0)
{
return false;
}
}
return true;
}
bool hws(int n)//判断回文数
{
int o=n,p=0;
while(o)
{
p=p*10+o%10;
o/=10;
}//翻转
if(p==n) return true;
else return false;
}
int main()
{
while(cin>>n)
{
cout<<2*n<<"\n";
if(ss(2*n) && hws(2*n))
{
return 0;
}
}
return 0;//完结撒花!
}
```