HDOJ 2117 Just a Numble(模拟除法)
Problem Description
Now give you two integers n m, you just tell me the m-th number after radix point in 1/n,for example n=4,the first numble after point is 2,the second is 5,and all 0 followed
Input
Each line of input will contain a pair of integers for n and m(1<=n<=10^7,1<=m<=10^5)
Output
For each line of input, your program should print a numble on a line,according to the above rules
Sample Input
4 2
5 7
123 123
Sample Output
5
0
8
开始想用JAVA的大数做的,可是超时了。。。
所以只有走上算法的路,用了模拟。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int m = sc.nextInt();
int sum = 1;
int t=0;
for(int i=0;i<m;i++){
if(sum==0){
t=0;
break;
}
sum = sum*10;
t = sum/n;
sum = sum%n;
}
System.out.println(t%10);
}
}
}
HDOJ 2117 Just a Numble(模拟除法)的更多相关文章
- hdu 2117:Just a Numble(水题,模拟除法运算)
Just a Numble Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- PTA——模拟除法
PTA 7-42 整除光棍 #include <stdio.h> int main() { ];//创建存表 ,count=; int n; ; scanf("%d", ...
- PAT 天梯赛 L1-046. 整除光棍 【模拟除法】
题目链接 https://www.patest.cn/contests/gplt/L1-046 思路 用同余定理以及模拟除法. AC代码 #include <iostream> #incl ...
- HDU 2117 Just a Numble
http://acm.hdu.edu.cn/showproblem.php?pid=2117 Problem Description Now give you two integers n m, yo ...
- PAT 团体程序设计天梯赛 L1-046 整除光棍(模拟除法)
L1-046. 整除光棍 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 翁恺 这里所谓的"光棍",并不是指单身汪 ...
- HDOJ 5402 Travelling Salesman Problem 模拟
行数或列数为奇数就能够所有走完. 行数和列数都是偶数,能够选择空出一个(x+y)为奇数的点. 假设要空出一个(x+y)为偶数的点,则必须空出其它(x+y)为奇数的点 Travelling Salesm ...
- HDOJ 5414 CRB and String 模拟
CRB and String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) T ...
- Gym-100814K 数位DP 模拟除法
Johnny is a brilliant mathematics student. He loves mathematics since he was a child, now he is work ...
- L1-046. 整除光棍(模拟除法)
题意: 这里所谓的“光棍”,并不是指单身汪啦~ 说的是全部由1组成的数字,比如1.11.111.1111等.传说任何一个光棍都能被一个不以5结尾的奇数整除.比如,111111就可以被13整除. 现在, ...
随机推荐
- 几种任务调度的 Java 实现方法与比较--转载
前言 任务调度是指基于给定时间点,给定时间间隔或者给定执行次数自动执行任务.本文由浅入深介绍四种任务调度的 Java 实现: Timer ScheduledExecutor 开源工具包 Quartz ...
- 【待解决】编译V8引擎出错-snapshot.cc
这几天学习nodejs,翻阅官网的API文档.看到nodejs插件时,想了解一下v8的实现机制,于是我便从GitHub社区克隆了一份v8源码库.哪知道,编译安装的时候就出了问题,这问题已经折磨我两天了 ...
- yii phpexcel <转>
原文详情参见 这里 1.下载phpexcel,将压缩包中的classes复制到protected/extensions下并修改为PHPExcel. 2.修改YII配置文件config/main.php ...
- colorAccent、colorPrimary、colorPrimaryDark actionbar toolbar navigationbar
伴随着Android5.0的发布也更新了support-v7-appcompat 到V21,其中增加了ToolBar.recyclerview.cardview等控件. Android5.0对改变AP ...
- U口破解指令介绍.
- Web api 文档以及测试工具配置
第一步: 创建web api 在nuget 上搜索 webapitestclient (包含预发行版) 然后在 /Areas/HelpPage/Views/Help/Api.cshtml 末尾 添加 ...
- 后台地址报错:Service Unavailable
首先考虑数据库是否打开? 第二重启IIS试试: 重启下iis试试(cmd接着iisreset) 再次访问就正常了,可以借鉴,但不一定就只是这一种原因.
- 我的github今天大手笔分享,welcome——fork
看项目名就知道是什么样子的demo,还包含了数据库文件,welcome fork!
- OC - 19.pthread和NSThread
简介 恰当的使用多线程编程可以提供任务的执行效率和系统资源的利用率 多线程是为了提高资源利用率,和应用程序的响应速度,多个线程共享应用资源 每个应用程序都有一个主线程,通常用来做UI界面刷新等 比较耗 ...
- 加入强调语气,使用<strong>和<em>标签
有了段落又有了标题,现在如果想在一段话中特别强调某几个文字,这时候就可以用到<em>或<strong>标签. 但两者在强调的语气上有区别:<em> 表示强调,< ...