zoukankan      html  css  js  c++  java
  • hdu 6734:Decimal

    http://acm.hdu.edu.cn/showproblem.php?pid=6734

    Problem Description

    Given a positive integer n, determine if 1n is an infinite decimal in decimal base. If the answer is yes, print “Yes” in a single line, or print “No” if the answer is no.

    Input

    The first line contains one positive integer T (1 ≤ T ≤ 100), denoting the number of test cases.
    For each test case:
    Input a single line containing a positive integer n (1 ≤ n ≤ 100).

    Output

    Output T lines each contains a string “Yes” or “No”, denoting the answer to corresponding test case.

    Sample Input

    2
    5
    3

    Sample Output

    No
    Yes

    Hint

    1/5 = 0.2, which is a finite decimal. 1/3 = 0.333 · · · , which is an infinite decimal.

    题意分析:

    给出数n,求1/n是否为无限小数.

    解题思路:

    模拟1/n的过程,如果一个余数出现了两次,那么一定会进入循环,小数一定是个无限小数.

    #include <bits/stdc++.h>
    using namespace std;
    bool book[120];
    int main()
    {
        int T, n;
        scanf("%d", &T);
        while(T--)
        {
            scanf("%d", &n);
            memset(book, false, sizeof(book));
            int x=1, temp=0;
            while(1)
            {
                if(x%n==0) {
                    temp=1;
                    break;
                }
                x=x%n;
                if(book[x]==true) {
                    temp=0;
                    break;
                }
                book[x]=true;
                x*=10;    
            }
            if(temp==1)
                printf("No
    ");
            else
                printf("Yes
    ");
        }
        return 0;
    } 
  • 相关阅读:
    杂记-2
    2019CSP-S游记
    csp2020
    特征根法小记
    csp模拟赛低级错误及反思
    备份
    黑科技——树剖两次dfs转一次dfs!
    输出天干地支
    蓝桥0531-输出Y
    蓝桥0615-判断四位数字前后两组是否相等
  • 原文地址:https://www.cnblogs.com/zyq1758043090/p/11852484.html
Copyright © 2011-2022 走看看