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

最新文章

  1. python与c互相调用
  2. MongoDB基础知识
  3. ldap配置记录
  4. uwsgi出现invalid request block size: 21573 (max 4096)...skip解决办法
  5. json提交数据到服务端
  6. java web统计当前访问用户数量
  7. jquery 文本域光标操作(选、添、删、取)
  8. MVC的JsonResult用法
  9. 比较X与Y的大小,绝对精准!!!!!!
  10. 织梦CMS(dedecms)栏目属性及系统封面模板、列表模板、文章模板区别和路径设置解答
  11. 【动态页面】(二)Java反射
  12. chromium源码阅读--Browser进程初始化
  13. Elasticsearch倒排索引结构
  14. AXI-Lite总线及其自定义IP核使用分析总结
  15. 第十六节:语法总结(3)(C#6.0和C#7.0新语法)
  16. C# winform程序怎么打包成安装项目(VS2010图解)
  17. Linux:“awk”命令的妙用
  18. 【NLP】MT中BLEU评分机制
  19. L0 Regularization
  20. MikroTik RouterOS 5.x使用HunterTik 2.3.1进行破解

热门文章

  1. POJ 3994:Probability One
  2. HDU 1003:Max Sum
  3. 在MFC做DLL动态链接库时,使用boost,出现断言错误
  4. 并发 ping
  5. Nginx、MySQL、PHP 编译安装
  6. 基于 burpsuite的web逻辑漏洞插件开发(来自JSRC安全小课堂,柏山师傅)
  7. iOS 多线程 GCD part3:API
  8. Docker部署NETCORE应用程序
  9. 寒假day22
  10. import datetime