博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ACM题目————A simple problem
阅读量:4650 次
发布时间:2019-06-09

本文共 1006 字,大约阅读时间需要 3 分钟。

Description

Zty很痴迷数学问题.。一天,yifenfei出了个数学题想难倒他,让他回答1 / n。但Zty却回答不了^_^. 请大家编程帮助他.
 

Input

第一行整数T,表示测试组数。后面T行,每行一个整数 n (1<=|n|<=10^5).
 

Output

输出1/n. (是循环小数的,只输出第一个循环节).
 

Sample Input

4
2
3
7
168
 

Sample Output

0.5
0.3
0.142857
0.005952380

 

和我名字那么相近的题目,当然要AC了!

 

//如果余数出现重复就表示有循环节#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int f[100000];int flag[100000];int main(){ int t,m,y,cnt,n,i; scanf("%d",&t); while(t--) { scanf("%d",&n); if(n<0) //如果是负数 { printf("-");//首先打印负号 n*=-1;//取反后当做正数处理 } if(n==1) { printf("1\n"); continue; } y=1; cnt=0; memset(flag,0,sizeof(flag));//初始化为0 flag[1]=1; while(y) { y*=10; f[cnt++]=y/n; y%=n; if(flag[y])//如果使用过,说明出现循环数节 break; flag[y]=1;//记录余数是否使用过 } printf("0."); for(i=0; i

 

转载于:https://www.cnblogs.com/Asimple/p/5521451.html

你可能感兴趣的文章
python的N个小功能(更新文件)
查看>>
【bzoj 4390】 [Usaco2015 dec]Max Flow(树上差分)
查看>>
java之sleep、wait、yield、join、notify乱解
查看>>
DEDECMS 关键字不能小于2个字节!
查看>>
Flutter学习笔记(10)--容器组件、图片组件
查看>>
gitlab 的使用策略和简单介绍
查看>>
Web.py Cookbook 简体中文版 - 保存上传的文件
查看>>
MongoDB学习笔记二—Shell操作
查看>>
Docker——入门实战
查看>>
UIView
查看>>
List 的一个有用的高效的操作 removeAll
查看>>
呵呵 不能相信
查看>>
jQuery小测验
查看>>
C#继承与多态
查看>>
关于面试总结2-SQL学生表
查看>>
Python小技巧
查看>>
fragment Activity之间传值的方法 之------------接口回调
查看>>
OSS研究
查看>>
Leetcode 116 Populating Next Right Pointers in Each Node
查看>>
Angular 1.63 双向数据绑定 通过 $http 发送数据
查看>>