小数第n位
如果我们把有限小数的末尾加上无限多个0,它们就有了统一的形式。
本题的任务是:在上面的约定下,求整数除法小数点后的第n位开始的3位数。
#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <vector>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std; typedef long long ll;
ll d = 1e10;
ll a;
int b,n;
int c;
int main() {
scanf("%lld%d%d",&a,&b,&n);
while(c < n) {
a %= b;
if(c + < n) {
a *= d;
c += ;
}
else {
a *= ;
c ++;
}
}
for(int i = ;i < ;i ++) {
printf("%d",a / b);
a %= b;
a *= ;
}
}
#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <vector>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std; typedef long long ll;
ll a;
int b,n;
int c;
int s = -;
int main() {
scanf("%lld%d%d",&a,&b,&n);
while(c < n) {
a %= b;
if(a == ) break;
if(a == s) {
n %= c;
c = ;
}
else if(s == -) s = a;
a *= ;
c ++;
}
for(int i = ;i < ;i ++) {
printf("%d",a / b);
a %= b;
a *= ;
}
}
小数第n位的更多相关文章
- 格式化 float 类型,保留小数点后1位
""" 练习 : 小明的成绩从去年的72分提升到了今年的85分,请计算小明成绩提升的百分点, 并用字符串格式化显示出'xx.x%',只保留小数点后1位: &qu ...
- php 不用四舍五入的方式截取小数点后两位
/** * 字符串截取, 默认小数点后2位 * @param $money * @param int $accuracy * @return float */ private function fil ...
- 控制input标签中只能输入数字以及小数点后两位
js 代码如下: /* 控制input标签中只能输入数字 和小数点后两位 */ function checkNum(obj) { //检查是否是非数字值 if (isNaN(obj.value)) { ...
- 关于Oracle中查询的数字值的显示格式需要保留小数点后两位(或者三位,及其他位数)
关于Oracle中查询的数字值的显示格式需要保留小数点后两位(或者三位,及其... 方法一:使用to_char的fm格式,即: to_char(round(data.amount,2),'FM9999 ...
- Double 数据保留两位小数二:直接截取小数后面两位,不进行四舍五入
package com; public class T2 { public static void main(String[] args) { System.out.println(calculate ...
- 限制EditText只能输入小数点后两位
设置EditText只能输入小数点后两位,在价格等有限制的输入时特别有效 TextWatcher textWatcher = new TextWatcher() { @Override public ...
- input内强制保留小数点后两位 位数不足时自动补0
input内强制保留小数点后两位 位数不足时自动补0 小数点后位数超出2位时进行四舍五入 需引入jquery包 1.11.2版本 1 function xiaoshu(x) 2 { 3 var f = ...
- js除法四舍五入保留小数点后两位写法
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- php number_format()保留小数点后几位
[PHP_保留两位小数的相关函数] php保留两位小数并且四舍五入 Php代码 1 $num = 123213.666666; 2 echo sprintf("%.2f ...
- Java float保留两位小数或多位小数
Java float保留两位小数或多位小数 方法1:用Math.round计算,这里返回的数字格式的. float price=89.89;int itemNum=3;float totalPr ...
随机推荐
- CCPC-Wannafly Winter Camp Day3 (Div2, onsite)
Replay Dup4: 没想清楚就动手写? 写了两百行发现没用?想的还是不够仔细啊. 要有莽一莽的精神 X: 感觉今天没啥输出啊, 就推了个公式?抄了个板子, 然后就一直自闭A. 语文差,题目没理解 ...
- poj1434 Fill the Cisterns!
地址:http://poj.org/problem?id=1434 题目:Fill the Cisterns! Fill the Cisterns! Time Limit: 5000MS Memo ...
- 去掉每行最后n个字符
awk '{sub(/.{n}$/,"")}1' nation.tbl > nation.tbl2 把n替换成具体长度
- C++多线程学习资料参考
新的C++11语法:<Professional C++>,或<C ++ Primer Plus>: C++11多线程:<C++ Concurrency in Actio ...
- 一次频繁Full GC问题排查过程分享
问题描述 应用收到频繁Full GC告警 问题排查 登录到对应机器上去,查看GC日志,发现YGC一分钟已经达到了15次,比Full GC还要频繁一些,其中Full GC平均10分钟超过了4次,如下图 ...
- WinterCamp2017 游记
Winter is coming! Day0 Day0前一天打了一轮CF,做完了ABCD,Div2 Rank59.然后就去开开心心的睡觉,准备第二天的行程. 快到一点的时候躺在了床上,睡不着,翻来覆去 ...
- GOEXIF读取和写入EXIF信息
最新版本的gexif,直接基于gdi+实现了exif信息的读取和写入,代码更清晰. /* * File: gexif.h * Purpose: cpp EXIF reader * 3/2/2017 & ...
- IntelliJ IDEA 常用快捷键,maven依赖图,个性化设置,禁用Search Everywhere
查看idea 中jar关系图 快捷键: Ctrl+/ 用于注释,取消注释 Ctrl+Shift+F 全文搜索 Ctrl+F 单页面查找 Ctrl+Alt+Shift+L 格式化代码 ======== ...
- Python学习札记(三十七) 面向对象编程 Object Oriented Program 8 @property
参考:@property NOTE 1.在绑定参数时,为了避免对属性不符合逻辑的操作,需要对传入的参数进行审核. #!/usr/bin/env python3 class MyClass(object ...
- python 字典的合并
d1 = {, } d2 = {, } d = d1.copy() d.update(d2) print(d)