Project Euler 820
题目
digit of Reciprocals
Let be the decimal digit of the
fractional part of , or if the fractional part has fewer than
digits. For example:
Let . You are
given:
Find .
解决方案
与第 731 题一样。如果要求分数 的第 位后的情况,那么相当于计算分数 的小数情况。这相当于直接将小数点右移了 位。
并且我们不需要知道分数 的整数部分。为了方便计算,就求 的小数部分。
令 ,那么 就是 第 位的小数值。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| #include <bits/stdc++.h> # include "tools.h" using namespace std; typedef long long ll; const int N=10000000;
int main(){ int ans=0; for(int k=1;k<=N;k++){ int x=qpow(10,N-1,k); ans+=x*10/k; } printf("%d\n",ans); }
|