小言_互联网的博客

(CCPC2019秦皇岛站--1004)Decimal(签到题)

400人阅读  评论(0)

原题目:

给定一个正整数 n,要求判断 1n 在十进制下是不是一个无限小数。如果是,输出“Yes”,否则输出“No”。

 

 

Input

输入第一行一个正整数 T,表示数据组数。

接下来 T 行,每行一个正整数 n(1≤n≤100)。
 

Hint


样例解释

15=0.2,不是无限小数。

13=0.333⋯,是无限小数。

 

 

Output

输出 T 行,每行一个字符串,表示对应测试数据的答案。

 

 

Sample Input


 

2 5 3

 

 

Sample Output


 

No Yes

水题,被输出坑了两发wa

原理:
只要被除数n可以转化为2的次幂或者转化为2与5的组合
即为有限小数 否则无限小数

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#define INF 0x3f3f3f3
#define MAX 10000000
using namespace std;
typedef long long ll;
int iint(int n) {
	if (n == 1)
		return 1;
	else if (n % 2 == 0) {
		return iint(n / 2);
	}
	else if (n % 5 == 0) {
		return iint(n / 5);
	}
	else {
		return 0;
	}
}
int main()
{
	int n,t;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		if (iint(n))
			printf("No\n");
		else
			printf("Yes\n");
	}
	return 0;
}

判断是否是有限小数模板

bool iint(int n)
{
    if(n==1) return false;
    else if(n%2==0)
    {
        return iint(n/2);
    }
    else if(n%5==0)
    {
        return iint(n/5);
    }
    else return true;
}

 


转载:https://blog.csdn.net/weixin_43791787/article/details/101629673
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场