Codeforces传送门
洛谷传送门
题目描述
Little X has met the following problem recently.
Let’s define
f(x)
f
(
x
)
as the sum of digits in decimal representation of number
x
x
(for example, ). You are to calculate
Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the following C++ code:
<br></br> ans = solve(l, r) % a;<br></br> if (ans \leq 0)<br></br> ans += a;<br></br><br></br>
ans = solve(l, r) % a;
if (ans \leq 0)
ans += a;
This code will fail only on the test with . You are given number
a
a
, help Little X to find a proper test for hack.
输入输出格式
输入格式:
The first line contains a single integer .
Print two integers: l,r(1 ≤ l ≤ r < 10200) l , r ( 1 ≤ l ≤ r < 10 200 ) — the required test data. Leading zeros aren’t allowed. It’s guaranteed that the solution exists.
输入输出样例
输入样例#1:
46
输出样例#1:
1 10
输入样例#2:
126444381000032
输出样例#2:
2333333 2333333333333
题目大意
给你一个数字 a a , 要求找到一段连续区间,使得区间中所有数的数位和为 a a 的倍数。 。
解题分析
真是毒瘤构造题专场…这场div1前三道都是构造…
直接构造是很难的, 我们想办法从一个固定的位置转移。
然后我们就能发现对于一个区间
[1,10n]
[
1
,
10
n
]
, 如果左右端点同时
+n
+
n
, 其数位和也同时
+n
+
n
。 这样我们就可以先得到一个较大的区间并计算其数位和, 再加上左右端点一段即可。
对于 [1,10n] [ 1 , 10 n ] , 其数位和为 10n−1×n×45+1 10 n − 1 × n × 45 + 1 。
代码如下(贴了一个高精的板QAQ):
#include <string>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#define R register
using namespace std;
namespace BigInteger
{
#define maxn 10005
struct Big_integer{
int d[maxn], len;
void clean() { while(len > 1 && !d[len-1]) len--; }
Big_integer() { memset(d, 0, sizeof(d)); len = 1; }
Big_integer(int num) { *this = num; }
Big_integer(char* num) { *this = num; }
Big_integer operator = (const char* num){
memset(d, 0, sizeof(d)); len = strlen(num);
for(int i = 0; i < len; i++) d[i] = num[len-1-i] - '0';
clean();
return *this;
}
Big_integer operator = (int num){
char s[10005]; sprintf(s, "%d", num);
*this = s;
return *this;
}
Big_integer operator + (const Big_integer& b){
Big_integer c = *this; int i;
for (i = 0; i < b.len; i++){
c.d[i] += b.d[i];
if (c.d[i] > 9) c.d[i]%=10, c.d[i+1]++;
}
while (c.d[i] > 9) c.d[i++]%=10, c.d[i]++;
c.len = max(len, b.len);
if (c.d[i] && c.len <= i) c.len = i+1;
return c;
}
Big_integer operator - (const Big_integer& b){
Big_integer c = *this; int i;
for (i = 0; i < b.len; i++){
c.d[i] -= b.d[i];
if (c.d[i] < 0) c.d[i]+=10, c.d[i+1]--;
}
while (c.d[i] < 0) c.d[i++]+=10, c.d[i]--;
c.clean();
return c;
}
Big_integer operator * (const Big_integer& b)const{
int i, j; Big_integer c; c.len = len + b.len;
for(j = 0; j < b.len; j++) for(i = 0; i < len; i++)
c.d[i+j] += d[i] * b.d[j];
for(i = 0; i < c.len-1; i++)
c.d[i+1] += c.d[i]/10, c.d[i] %= 10;
c.clean();
return c;
}
Big_integer operator / (const Big_integer& b){
int i, j;
Big_integer c = *this, a = 0;
for (i = len - 1; i >= 0; i--)
{
a = a*10 + d[i];
for (j = 0; j < 10; j++) if (a < b*(j+1)) break;
c.d[i] = j;
a = a - b*j;
}
c.clean();
return c;
}
Big_integer operator % (const Big_integer& b){
int i, j;
Big_integer a = 0;
for (i = len - 1; i >= 0; i--)
{
a = a*10 + d[i];
for (j = 0; j < 10; j++) if (a < b*(j+1)) break;
a = a - b*j;
}
return a;
}
Big_integer operator += (const Big_integer& b){
*this = *this + b;
return *this;
}
bool operator <(const Big_integer& b) const{
if(len != b.len) return len < b.len;
for(int i = len-1; i >= 0; i--)
if(d[i] != b.d[i]) return d[i] < b.d[i];
return false;
}
bool operator >(const Big_integer& b) const{return b < *this;}
bool operator<=(const Big_integer& b) const{return !(b < *this);}
bool operator>=(const Big_integer& b) const{return !(*this < b);}
bool operator!=(const Big_integer& b) const{return b < *this || *this < b;}
bool operator==(const Big_integer& b) const{return !(b < *this) && !(b > *this);}
string str() const{
char s[maxn]={};
for(int i = 0; i < len; i++) s[len-1-i] = d[i]+'0';
return s;
}
};
istream& operator >> (istream& in, Big_integer& x)
{
string s;
in >> s;
x = s.c_str();
return in;
}
ostream& operator << (ostream& out, const Big_integer& x)
{
out << x.str();
return out;
}
}
using namespace BigInteger;
Big_integer bg, ed, dat;
int main(void)
{
cin >> dat; bg = 1;
Big_integer base = 10, mul = 10;
for (R int i = 1; i <= 18; ++i) base = base * mul;
ed = base;//10 ^ 19
mul = 45;
base = 19;
mul = mul * base;
base = 10;
for (R int i = 1; i <= 18; ++i) mul = mul * base;
mul = mul + bg;
Big_integer mod = mul % dat;
Big_integer cha = dat - mod;
cout << (bg + cha) << " " << (ed + cha);
}