PE 145 How many reversible numbers are there below one-billion? (暴力)
2016-12-27 19:51
375 查看
How many reversible numbers are there below one-billion?
Problem 145
Some positive integers n have the property that the sum [ n + reverse(n) ] consists entirely of odd (decimal) digits. For instance, 36 + 63 = 99 and 409 + 904 = 1313. We will call such numbers reversible;so 36, 63, 409, and 904 are reversible. Leading zeroes are not allowed in either n or reverse(n).
There are 120 reversible numbers below one-thousand.
How many reversible numbers are there below one-billion (109)?
题意:
有多少小于十亿的可逆数?
有些正整数n满足这样一种性质,将它的数字逆序排列后和本身相加所得到的和[ n + reverse(n) ]的十进制表示只包含有奇数数字。例如,36 + 63 = 99 以及409 + 904 = 1313。我们称这样的数是可逆的;因此36,63,409和904都是可逆的。无论是n还是reverse(n)都不允许出现前导0。
在小于一千的数中,一共有120个可逆数。
在小于十亿(109)的数中,一共有多少个可逆数?
题解:感觉没什么好说的....直接暴力....
其实一亿到10亿之间是没有可逆数的。然后暴力到一亿就可以了。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int reverse(ll x)
{
ll r=0;
while (x>0)
{
r=r*10+(x%10);
x/=10;
}
return r;
}
int check_odd(ll x)
{
int flag=0;
while (x>0)
{
if ((x%10)%2==0){
flag=1;
break;
}
x/=10;
}
if (flag) return 0;
else return 1;
}
int main()
{
ll count=0;
//在 1 亿到 10亿之间没有可逆数
for (ll i=10;i<=100000000;i+=2)
{
if (check_odd(i+reverse(i)) && i%10!=0)
count++;
}
cout<<count*2<<endl;
return 0;
}
相关文章推荐
- projecteuler No.145 How many reversible numbers are there below one-billion?
- Problem 15 - Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner?
- hdoj How many prime numbers (素数判断&暴力)
- HDU 3191 How Many Paths Are There(SPFA)
- 剑桥少儿英语一级教案(上) Unit4 How many ducks are there?
- HDU 4627 There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number.
- HDU-3191 How Many Paths Are There 次最短路
- hdu3191 How Many Paths Are There
- hdu6181 How Many Paths Are There(次短路条数[模板])
- HDU 3191 How Many Paths Are There 【次短路计数】
- HDU3191-How many paths are there(次短路的长度及其个数)
- hdu3191 How Many Paths Are There(次短路计数dp)
- hdu 1688 Sightseeing (次短路及次短路数)&&pku3255 Roadblocks &&3191 How Many Paths Are There
- hdu 3191 How Many Paths Are There (次短路径数)
- How Many Paths Are There
- hdu 3191 How Many Paths Are There(求次短路径和次短路径条数)
- hdu 3191 How Many Paths Are There(次短路) 很纠结题目。。。
- hdoj--2138--How many prime numbers(暴力模拟)
- HDU 3191 How Many Paths Are There
- HDU-3191 How Many Paths Are There(有向图次短路条数)