当前位置:网站首页>AtCoder—E - Σ[k=0..10^100]floor(X/10^k
AtCoder—E - Σ[k=0..10^100]floor(X/10^k
2022-07-31 10:18:00 【MITBlick】
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 500500 points
Problem Statement
Find \displaystyle \sum_{k=0}^{10^{100}} \left \lfloor \frac{X}{10^k} \right \rfloork=0∑10100⌊10kX⌋.
Notes
\lfloor A \rfloor⌊A⌋ denotes the value of AA truncated to an integer.
Constraints
- XX is an integer.
- 1 \le X < 10^{500000}1≤X<10500000
Input
Input is given from Standard Input in the following format:
XX
Output
Print the answer as an integer.
Here, the answer must be precisely printed as an integer, even if it is large. It is not allowed to use exponential notation, such as 2.33e+21, or print unnecessary leading zeros, as in 0523.
Sample Input 1 Copy
Copy
1225
Sample Output 1 Copy
Copy
1360
The value we seek is 1225+122+12+1+0+0+\dots+0=13601225+122+12+1+0+0+⋯+0=1360.
Sample Input 2 Copy
Copy
99999
Sample Output 2 Copy
Copy
111105
Beware of carries.
Sample Input 3 Copy
Copy
314159265358979323846264338327950288419716939937510
Sample Output 3 Copy
Copy
349065850398865915384738153697722542688574377708317
The values in input and output can both be enormous.
解题思路:估计你看到下面这张图图之后就恍然大悟了。

这里我们很容易看到两个绿圈的规律。
Code:
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
const int N = 100010;
typedef long long LL;
int n, m, sum, cnt;
string s, t;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s;
for(int i = 0; i < s.size(); i ++ ) sum += s[i] - '0'; //绿圈求和
for(int i = s.size() - 1; i >= 0; i -- )
{
cnt += sum; //每次循环后的绿圈求和
t.push_back((cnt % 10) + '0');
cnt /= 10;
sum -= s[i] - '0';
}
if(cnt) t.push_back(cnt + '0');
reverse(t.begin(), t.end());
cout << t << endl;
}边栏推荐
猜你喜欢
随机推荐
csdn file export to pdf
“chmod 777-R 文件名”什么意思?
loadrunner录制问题
【LeetCode】141.环形链表
csdn文件导出为pdf
透过开发抽奖小程序,体会创新与迭代
Redis Cluster - Sentinel Mode Principle (Sentinel)
Come n times - 07. Rebuild the binary tree
Single sign-on principle and implementation
Come n times with the sword--05. Replace spaces
Simple understanding of GCD
Mybaits 常用问题详解
可以用聚酯树脂将接线板密封接线盒吗?(接线盒灌封胶用哪种树脂)
loadrunner-Controller负载测试-各模块功能记录01测试场景设计
恋爱期间的赠与能否撤销
【JWT】JWT 整合
因存在自燃安全隐患,宝马7系和5系紧急召回,合计超过5.7万辆
Summary of three methods for SQL deduplication
开放麒麟 openKylin 自动化开发者平台正式发布
如何将虚拟机上的文件复制到主机上









