zoukankan      html  css  js  c++  java
  • 2019CCPC秦皇岛D题 Decimal

    Decimal

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
    Total Submission(s): 103    Accepted Submission(s): 49


    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.
     
    Source

    题解:
    问1/n是否是有限小数,队友很快反应过来找n是否含有非2和非5的因子。
    参考代码:
     
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int n;
            scanf("%d",&n);
            if(n%5==0)
            {
                do{
                    n/=5;
                }while(n%5==0);
            }
            if(n%2==0)
            {
                do{n/=2;}while(n%2==0);
            }
            if(n==1) puts("No");
            else puts("Yes");
        }
        return 0; 
    }
    View Code
  • 相关阅读:
    CopyOnWriteArrayList分析
    java锁和同步
    线程池原理
    Hadoop1的安装
    Hadoop2的HA安装(high availability):JournalNode+ zookeeper
    Hadoop2的HA安装(high availability):nfs+zookeeper
    Hadoop2的FN安装(federated namespace)
    Redis 基础知识
    mycat
    GitFlow及项目工作流程
  • 原文地址:https://www.cnblogs.com/csushl/p/11604651.html
Copyright © 2011-2022 走看看