不想说什么,输入只有不到300种,直接暴力打表吧。
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
//int wei;
int a[7][60] =
{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 2, 2, 0, 2, 3, 0, 3, 3, 0, 1, 1, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 0, 2, 4, 0, 7, 7, 0, 12, 13, 0, 16, 16, 0, 13, 18, 0, 12, 11, 0, 6, 4,0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 4, 8, 0, 20, 19, 0, 31, 52, 0, 67, 77, 0, 93, 101, 0, 116, 95, 0, 92, 91, 0, 63, 51, 0, 29, 30, 0, 16, 5, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 4, 12, 0, 28, 45, 0, 95, 143, 0, 236, 272, 0, 411, 479, 0, 630, 664, 0, 742, 757, 0, 741, 706, 0, 580, 528, 0, 379, 341, 0, 205, 166, 0, 84, 62, 0,34, 13, 0, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 2, 14, 0, 58, 76, 0, 204, 389, 0, 660, 852, 0, 1448, 1971, 0, 2832,3101, 0, 4064, 4651, 0, 5393, 5376, 0, 5570, 5785, 0, 5287, 4796, 0, 3975, 3671, 0, 2687, 2080, 0, 1405, 1135, 0, 630, 405, 0, 178, 140, 0, 51, 16, 0, 3, 1, 0,0, 0, 0, 0, 0}
};
/*
int getSum(int n)
{
int sum = 0;
wei = 0;
while(n != 0)
{
sum += n % 10;
n = n / 10;
wei++;
}
return sum;
}
*/
int main()
{
int i;
int te;
int s;
int b;
int sum;
int d;
int j;
/*
for(i = 2; i < 1000000; i++)
{
d = 1;
for(j = 2; j <= (int)sqrt(i) && d == 1; j++)
{
if(i % j == 0)
{
d = 0;
continue;
}
}
if(d == 1)
{
sum = getSum(i);
a[wei][sum]++;
}
}
for(i = 0; i < 7; i++)
{
printf("{");
for(j = 0; j < 60; j++)
{
printf("%d, ", a[i][j]);
}
printf("}");
printf("\n");
}
*/
scanf("%d", &te);
while(te--)
{
scanf("%d %d", &s, &b);
if(b <= 60)
{
printf("%d\n", a[s][b]);
}
else
{
printf("0\n");
}
}
return 0;
}