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

 

posted @ 2019-09-28 20:09  StarHai  阅读(650)  评论(0编辑  收藏  举报