then he gets the result
As Ruins is forgetful, a few seconds later, he only remembers KK, xx and forgets yy. please help him find how many yy satisfy x=f(y,K)−yx=f(y,K)−y.
Every test case contains one line with two integers xx, KK.
Limits
1≤T≤1001≤T≤100
0≤x≤1090≤x≤109
1≤K≤91≤K≤9 OutputFor 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 2Sample 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;
}