zoukankan      html  css  js  c++  java
  • 河南多校大一训练赛 D

    题目链接:http://acm.hust.edu.cn/vjudge/contest/125004#problem/D

    密码:acm

    Description

    If an integer is not divisible by 2 or 5, some multiple of that number in decimal notation is a sequence of only a digit. Now you are given the number and the only allowable digit, you should report the number of digits of such multiple.

    For example you have to find a multiple of 3 which contains only 1's. Then the result is 3 because is 111 (3-digit) divisible by 3. Similarly if you are finding some multiple of 7 which contains only 3's then, the result is 6, because 333333 is divisible by 7.

    Input

    Input starts with an integer T (≤ 300), denoting the number of test cases.

    Each case will contain two integers n (0 < n ≤ 106 and n will not be divisible by 2 or 5) and the allowable digit (1 ≤ digit ≤ 9).

    Output

    For each case, print the case number and the number of digits of such multiple. If several solutions are there; report the minimum one.

    Sample Input
    3
    3 1
    7 3
    9901 1
    Sample Output
    Case 1: 3
    Case 2: 6
    Case 3: 12

    分析:

    第一次代码,超了应该,反正看输不出结果:

     1 #include<cstdlib>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<cmath>
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     int n,i,o=1,a,b;
    11     scanf("%d", &n);
    12 
    13     for(i=1;i<=n;i++)
    14     {
    15         scanf("%d%d", &a,&b);
    16         int d=b,ans=1;
    17 
    18         while(d%a)
    19         {
    20             d=d*10+b;
    21             ans++;
    22         }
    23 
    24         printf("Case %d: %d
    ", o++,ans);
    25     }
    26     return 0;
    27 }

    修改后:

     1 #include<cstdlib>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<cmath>
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     int n,i,o=1,a,b;
    11     scanf("%d", &n);
    12 
    13     for(i=1;i<=n;i++)
    14     {
    15         scanf("%d%d", &a,&b);
    16         int d=b,ans=1,r;
    17 
    18         r=b%a;
    19         while(r)
    20         {
    21             d=r*10+b;
    22             ans++;
    23             r=d%a;
    24         }
    25 
    26         printf("Case %d: %d
    ", o++,ans);
    27     }
    28     return 0;
    29 }
  • 相关阅读:
    Python Day13:开放封闭原则、函数装饰器、全局局部变量
    Python Day12
    Python Day11
    Python Day10
    drf框架
    drf框架
    drf框架
    drf框架
    vue框架
    vue框架
  • 原文地址:https://www.cnblogs.com/weiyuan/p/5721418.html
Copyright © 2011-2022 走看看