PE 145 How many reversible numbers are there below one-billion? (暴力)

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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值