ACM-简单题之Just a Numble——hdu2117
来源:互联网 发布:知乎 人力资源部门前景 编辑:程序博客网 时间:2024/05/22 10:31
Just a Numble
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2106 Accepted Submission(s): 986
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
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2106 Accepted Submission(s): 986
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
这道题,怎么说呢,第一次看,有点吓到啊,
被m,n范围,
又是一道大数题了么。。o(╯□╰)o
好讨厌的说。。。
算一算怎么解呢?后来发现,就模拟除法运算,很简单就算出来了。
比如当n=4, 首先判断1%4==0 不相等,
按照除法规则就需要 将余数乘以10 再判断,而余数1乘以10 再除以4得到的便是小数点后第一个数,
再判断余数1乘以10以后的数与4取余是否等于0,不等就再次循环。
啊,还要注意碰到无限循环小数,你就悲剧了,所以,要利用m,
题目求第m个位置,我们就算到第m个位置结束,break就OK了,
嘿嘿,又AC一道题啦O(∩_∩)O~
//just a numble#include <iostream>#include <string.h>using namespace std;int arr[100001];void set_arr(int n,int m){memset(arr,0,sizeof(arr));int i,j,k;i=k=1;while((k=k%n)!=0){k*=10;arr[i]=k/n;++i;// 如果i大于m,不管是有限小数还是无限的,全跳出来if(i>m)break;}return;}int main(){int n,m;int i,j,len;while(cin>>n>>m){set_arr(n,m);cout<<arr[m]<<endl;}return 0;}
0 0
- ACM-简单题之Just a Numble——hdu2117
- hdu2117 Just a Numble
- HDU2117 Just a Numble
- Just a Numble
- Just a Numble
- Just a Numble
- Just a Numble 2117
- Just a Numble
- HDOJ2117 Just a Numble
- hdu 2117 Just a Numble
- hdu 2117 Just a Numble
- hdu 2117 Just a Numble
- hdu 2117 Just a Numble
- Just a Numble HDU 2117
- HDU 2117 Just a Numble
- hdu-2117-Just a Numble
- HUD-2117-Just a Numble
- HDOJ 2117 Just a Numble
- 由UITableView reloadData后引起的界面布局问题分析
- 基本模版
- 学校1095: 大内密探零零发的密码
- 超链接
- 按钮和导航条
- ACM-简单题之Just a Numble——hdu2117
- 调试js 试用火狐的firebug
- 列表页
- 开源浏览器:Dillo Web Browser简介
- 对话框
- Linux分区的命名--/dev/xxyN
- 旁注虚拟主机IIS权限重分配跨目录得webshell
- Android Asynchronous Http Client-Android异步网络请求客户端接口
- hdu n皇后问题 (dfs)