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

原题目:

给定一个正整数 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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

deebcjrb

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值