判断1/N是否为无限小数
2024-10-08 17:22:07
给定一个正整数N,请判断1/N是否为无限小数,若是输出YES,若不是请输出NO。
思路:
只要被除数n可以转换成2的次幂或者2与5的组合即为有限小数,否则为无线小数
代码如下:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
//const double PI=acos(-1);
#define Bug cout<<"---------------------"<<endl
const int maxn=5e5+;
using namespace std; int judge(int n)
{
while(n)
{
if(n%==||n==)
{
n/=;
}
else
break;
}
while(n)
{
if(n%==||n==)
{
n/=;
}
else
break;
}
if(n==)
return ;
else
return ;
} int main()
{
int n;
scanf("%d",&n);
if(judge(n))
printf("NO\n");
else
printf("YES\n");
return ;
}
递归写法:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
//const double PI=acos(-1);
#define Bug cout<<"---------------------"<<endl
const int maxn=5e5+;
using namespace std; int Solve(int n)
{
if(n==)
return ;
else if(n%==)
return Solve(n/);
else if(n%==)
return Solve(n/);
else
return ;
} int main()
{
int n;
scanf("%d",&n);
if(Solve(n))
printf("NO\n");
else
printf("YES\n");
return ;
}
最新文章
- python与c互相调用
- MongoDB基础知识
- ldap配置记录
- uwsgi出现invalid request block size: 21573 (max 4096)...skip解决办法
- json提交数据到服务端
- java web统计当前访问用户数量
- jquery 文本域光标操作(选、添、删、取)
- MVC的JsonResult用法
- 比较X与Y的大小,绝对精准!!!!!!
- 织梦CMS(dedecms)栏目属性及系统封面模板、列表模板、文章模板区别和路径设置解答
- 【动态页面】(二)Java反射
- chromium源码阅读--Browser进程初始化
- Elasticsearch倒排索引结构
- AXI-Lite总线及其自定义IP核使用分析总结
- 第十六节:语法总结(3)(C#6.0和C#7.0新语法)
- C# winform程序怎么打包成安装项目(VS2010图解)
- Linux:“awk”命令的妙用
- 【NLP】MT中BLEU评分机制
- L0 Regularization
- MikroTik RouterOS 5.x使用HunterTik 2.3.1进行破解