Difference HDU - 5936

Little Ruins is playing a number game, first he chooses two positive integers  y y and  K K and calculates  f(y,K) f(y,K), here 

f(y,K)=z in every digits of yzK(f(233,2)=22+32+32=22) f(y,K)=∑z in every digits of yzK(f(233,2)=22+32+32=22)


then he gets the result 

x=f(y,K)y x=f(y,K)−y


As Ruins is forgetful, a few seconds later, he only remembers  K K x x and forgets  y y. please help him find how many  y y satisfy  x=f(y,K)y x=f(y,K)−y.
Input
First line contains an integer  T T, which indicates the number of test cases. 

Every test case contains one line with two integers  x x K K

Limits 
1T100 1≤T≤100 
0x109 0≤x≤109 
1K9 1≤K≤9
Output
For every test case, you should output  'Case #x: y', where  x indicates the case number and counts from  1 and  y is the result.
Sample Input
2
2 2
3 2
Sample Output
Case #1: 1

Case #2: 2

#include<iostream>
using namespace std;
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<map>
#define LL long long

const int e[]={1, 10, 100, 1000, 10000, 100000};

int mi[13][13];
map<LL,int>coun[10];
void init()
{
      for(int i=0;i<10;i++){
         mi[0][i]=1;
        for(int j=1;j<10;j++)mi[j][i]=mi[j-1][i]*i;
    }
    for(int i=1;i<10;i++)
    {
        for(int j=0;j<e[5];j++)
        { LL sum=-j;
            for(int t=0;t<=4;++t)
                sum+=mi[i][j/e[t]%10];
             coun[i][sum]++;
        }
    }
}
int main() {
     init();
     int T;
    scanf("%d",&T);
    for(int k=1; k<=T; k++) {
        int x,b;
        LL ans=0;
       scanf("%d%d",&x,&b);
        for(int i=0;i<100000;i++)
        {
            LL c,d;
            d=-(LL)i*100000;
             for(int j=0;j<=4;++j)
            d+=mi[b][i/e[j]%10];
            c=x-d;
            if(coun[b].find(c)!=coun[b].end())//这里画重点,不知道为什么加就对,不加就不对,
            ans=ans+coun[b][c];			//如果知道可以评论。
        }
        if(x==0)
            ans--;
        printf("Case #%d: %lld\n",k,ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值