2011-09-22 08:44:13Morris
a240. 第一題:1 / 17 小數第 n 位
a240. 第一題:1 / 17 小數第 n 位
/* Language: C (291 Bytes) */
/* Result: AC(0ms, 232KB) judge by this@ZeroJudge */
/* Author: morris1028 at 2011-09-22 06:57:06 */
/**********************************************************************************/
#include<stdio.h>
main() {
char cycle[20] = "70588235294117647";
int t, n, sum, i;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
printf("%c ", cycle[n%16]);
sum = 72*(n/16);
for(i = n%16; i >= 1; i--)
sum += cycle[i]-'0';
printf("%d\n", sum);
}
return 0;
}
內容 :
請寫一個程式,輸入正整數n求若將 1 / 17 化為小數﹐則小數點後第n位數字為多少?及小數點後第1位至第n位的數字和為多少?
輸入說明
:
有m(1≤m≤5)組測試資料且1≤n≤170000,每組測試資料均為一行
接下來共有m行,每行有1個整數。
輸出說明
:
對於每一組測試資料,輸出一行2個數字(空格隔開),代表著這個第n位數字及小數點後第1位至第n位的其數字和。
範例輸入 :
2 3 5
範例輸出 :
8 13 2 23
提示
:
出處
:
板橋高中2011能力競賽
(管理:snail)
/**********************************************************************************/
/* Problem: a240 "第一題:1 / 17 小數第 n 位" from 板橋高中2011能力競賽*//**********************************************************************************/
/* Language: C (291 Bytes) */
/* Result: AC(0ms, 232KB) judge by this@ZeroJudge */
/* Author: morris1028 at 2011-09-22 06:57:06 */
/**********************************************************************************/
#include<stdio.h>
main() {
char cycle[20] = "70588235294117647";
int t, n, sum, i;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
printf("%c ", cycle[n%16]);
sum = 72*(n/16);
for(i = n%16; i >= 1; i--)
sum += cycle[i]-'0';
printf("%d\n", sum);
}
return 0;
}