整数对问题

来源:互联网 发布:淘宝薇薇家叶罗丽娃娃 编辑:程序博客网 时间:2024/05/16 00:11
/*
 * 整数对问题
 * tanliboy <tanliboy2003@yahoo.com.cn> Nov.26 2008
 */
#include<iostream>
#include<vector>
using namespace std;

long pow(int cnt)
{
    long res = 1;
    while(cnt--)
    {
        res *= 10;
    }
    return res;
}

int main()
{
    long N;
    cin>>N;

    int len = 0;
    long num = N;
    while(num>0)
    {
        num/=10;
        len++;
    }

    for(int base = 0;base < len ;base++)
    {
        for(int n = 0;n<=9;n++)
        {
            if(0 == n && base == len-1)
            {
                // the first number can't be 0.
                continue;
            }

            long radix = pow(base);
            long num = N - n * radix;
            long a = num/radix;
            a/=11;

            if(a<0 )
            {
                continue;
            }

            long b = num - a * radix * 11;
            if(b<0 || 0!= b%2 || radix <= b/2)
            {
                continue;
            }
            b/=2;
           
            cout<<(a*10 + n)*radix +b<<"  + "<<a*radix + b <<"  =  "<<N<<endl;
        }
    }

}