A. 这是一道简单的水题~

来源:互联网 发布:seo一专员 编辑:程序博客网 时间:2024/05/22 08:24

A. 这是一道简单的水题~

pbz最近沉浸在数学中无法自拔,他发现了一种非常有趣的数,这个数的十进制表示形式中只含有8和9,这个数有着很好的寓意,代表了pbz的梦想和期望,他想知道对于任意的给定的正整数N,有多少个正整数M使得N*M所得得数是pbz所想要的数。
Input
第一行给出一个T,表示有T组案例,每个测试用例由一行组成,每行输入一个正整数N(1<=N*M<=1e10)

Output
对于每个输入的N,按升序输出所有符合条件的M,如果M不存在的话就输出“\This is not of value!\”。

Sample Input
2
5
9
Sample Output
\This is not of value!\
1
11
111
1111
11111
111111
1111111
11111111
98765432
111111111
987654321
987654322
987654332
987654432
987655432
987665432
987765432
988765432
998765432
1098765432
1111111111

只有 8 9 两个选择bfs就好

#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<string>#include<algorithm>#include<stack>#include<queue>#include<cctype>#include<functional>using namespace std;#define swap(a,b) {long long c=a;a=b;b=c;}const int MAX = 999999;const double Eps = 1e-12;const double PI = acos(-1.0);int gcd(int x, int y){    return x%y == 0 ? y : gcd(y, x%y);}long long num[1000005] = { 8,9 };long long j;int main(){    j = 2;    long long i;    for ( i = 0;;i++)    {        num[j++] = num[i] * 10 + 8;        if (num[j - 1]>10000000000)            break;        num[j++] = num[i] * 10 + 9;        if (num[j - 1]>10000000000)            break;    }    int t;    scanf("%d", &t);    while (t--)    {        long long n;        scanf("%lld", &n);        int flag = 0;        for (int i = 0;i<j;i++)        {            if (num[i] % n == 0 && num[i] <= 1e+10)            {                flag = 1;                printf("%lld\n", num[i] / n);            }            if (num[i]>10000000000)break;        }        if (flag==0)                printf("\\This is not of value!\\\n");    }    return 0;}
原创粉丝点击