Submission #3629686
Source Code Expand
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; constexpr ld eps = 1e-18; int main() { ll k; cin >> k; auto calc = [] (ll x) { ll tx = x, sum = 0; while(x > 0) { sum += x % 10; x /= 10; } return (ld) tx / sum; }; auto f = [&calc] (ll x) { int d = 0; { auto tx = x; while(tx > 0) tx /= 10, d += 1; } ll y = 10; ll res = x; for(int i = 0; i < d; ++i) { const auto z = y * (x / y + 1) - 1; if(z <= x) continue; if(fabs(calc(res) - calc(z)) < eps) { res = min(res, z); } else if(calc(res) > calc(z)) { res = z; } y *= 10; } return res; }; ll x = 1; for(int i = 0; i < k; ++i) { cout << x << endl; x = f(x + 1); } }
Submission Info
Submission Time | |
---|---|
Task | D - Snuke Numbers |
User | Suibaka |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 1000 Byte |
Status | AC |
Exec Time | 4 ms |
Memory | 256 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample.txt |
All | sample.txt, 1.txt, sample.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
1.txt | AC | 4 ms | 256 KB |
sample.txt | AC | 1 ms | 256 KB |