题意:输入整数a和b,输出a/b的循环小数以及循环节的长度

学习的这一篇

http://blog.csdn.net/mobius_strip/article/details/39870555

因为n%m的余数只可能是0到m-1中的一个,根据抽屉原理,当计算m+1次时至少存在一个余数相同

发现看了题解理解起来也好困难啊,

后来手动画了一下5/7的竖式除法的式子,,理解一些了

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i) typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int vis[maxn],r[maxn],s[maxn]; int main(){
int n,m;
while(cin>>n>>m){
memset(vis,,sizeof(vis));
memset(r,,sizeof(r));
memset(s,,sizeof(s)); int cnt=;
int t=n;
r[cnt++]=n/m;
n=n%m;
while(!vis[n]&&n){
vis[n]=cnt;
s[cnt]=n;//s数组存的是对应的余数
r[cnt++]=n*/m;//r数组存的是对应的商
n=n*%m;
} printf("%d/%d = %d.",t,m,r[]); for(int i=;i<cnt&i<=;i++){
if(s[i]==n&&n) printf("(");
printf("%d",r[i]);
}
if (!n) printf("(0");
if (cnt > ) printf("...");
printf(")\n");
printf(" %d = number of digits in repeating cycle\n\n",!n?:cnt-vis[n]);
}
return ;
}

还得再多画一画----好晕--------------

写模拟写得好难受------------

goooooooooooooo----------

最新文章

  1. asp.net MVC 应用程序的生命周期
  2. 通过正则表达式实现简单xml文件解析
  3. 介绍开源的.net通信框架NetworkComms框架 源码分析(十三)ThreadSafeStream
  4. dolby逝世:纪念一下
  5. java ConcurrentModificationException探究
  6. [转载]推荐不伤眼睛的文字背景色 VS背景色
  7. 关于easyUI在子页面增加显示tabs的一个问题
  8. (转)ubuntu下如何查看和设置分辨率
  9. Mongodb安装和基本命令
  10. AutoCAD 2014简体中文版官方正式版x86 x64下载,带注册机,永久免费使用
  11. ORA-12516 TNS监听程序找不到符合协议堆栈要求的可用处理程序
  12. html中object标签详解
  13. Customer segmentation – LifeCycle Grids with R(转)
  14. SQL查询语句优化的实用方法
  15. 记一次Nginx+Keepalived高可用故障转移
  16. 微信小程序页面带参数跳转
  17. jquery对象和DOM对象的相互转换详解
  18. netty 的 JBoss Marshalling 编码解码
  19. 【LOJ#10154】选课
  20. 使用shell脚本监控用户登陆服务器并发送提示信息给微信

热门文章

  1. 机器翻译引擎的基本原理 ——LSTM
  2. Python入门机器学习
  3. BOOL的getter方法
  4. Python学习之基本概念
  5. POJ 3320 Jessica&#39;s Reading Problem (尺取法,时间复杂度O(n logn))
  6. Codeforces 845A. Chess Tourney 思路:简单逻辑题
  7. php如何实现文件下载
  8. size_type类型
  9. 在学校机房联想硬盘保护下安装Linux,并配置锐捷客户端
  10. Python+Appium来写app自动化脚本