Alice and Bob,Alice喜欢n位数,Bob喜欢能被m整除的数

问题描述:

题目描述
Alice喜欢n位数,Bob喜欢能被m整除的数,请问被Alice和Bob都喜欢的数有多少个?

输入
第一行是一个整数K(K≤10000),表示样例的个数。
每个样例是一行,两个整数n(1≤n≤18),m(2≤m≤1000000)。

输出
每行输出一个样例的结果。

样例输入
4
1 2
3 2
3 3
3 10000
样例输出
5
450
300
0

#include<stdio.h>
#include<math.h>
int main()
{
    int c,f,a,b,n,i;
    int e=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&a,&b);//a-Alice,b-Bob
        c=pow(10,a);
        f=pow(10,a-1);
        e=(c-f)/b;
        printf("%d\n",e);
        e=0;
    }
    return 0;
}

结果是Wrong Answer,哪里错了?

供参考


#include <stdio.h>
#include <math.h>
int main()
{
    int k;
    __int64 a,b,count;
    scanf("%d", &k);
    while (k--)
    {
        int n, m;
        scanf("%d%d", &n, &m);
        if (n == 1)
        {
            count = 9 / m+1;
            printf("%I64d\n", count);
        }
        else
        {
            
            a = pow(10, n) - 1;
            a = a / m;
            b = pow(10, n - 1) - 1;
            b = b / m;
            count = a - b;
            printf("%I64d\n", count);
        }
    }
    return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
int a,b,n;
long long c,f,e=0;
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&a,&b);//a-Alice,b-Bob
c=pow(10,a);
f=pow(10,a-1);
e=(c-f)/b;
if(a==1)
{
e=e+1;
}
printf("%lld\n",e);
e=0;
}
return 0;
}

最大输入位数18,int装不下18位数,溢出了