Live2D

题解 CF468C Hack it!

题目传送门

Description

\(f(i)\) 表示 \(i\) 的数码只和,给出 \(a\),求出 \(l,r\) 使得 \(\sum_{i=l}^{r} f(i)\equiv 0\pmod{a}\)

Solution

md,为什么会有人想出这么妙的题啊????

我们首先可以看出,\(i<10^{18}\rightarrow f(i+10^{18})=f(i)+1\),那么我们就可以知道:

\[\sum_{i=1}^{10^{18}}\equiv \sum_{i=1}^{10^{18}-1}+f(0)+1\equiv \sum_{i=0}^{10^{18}-1} f(i)+1\equiv p+1\pmod{a} \]

同理,我们可以推出:

\[\sum_{i=2}^{10^{18}+1}\equiv p+2\pmod{a} \]

\[\sum_{i=3}^{10^{18}+2}\equiv p+3\pmod{a} \]

.
.
.
.
.

\[\sum_{i=a-p}^{10^{18}+a-p-1}\equiv p+a-p\equiv 0\pmod{a} \]

问题就是如何求 \(p\),我们只需要对于每一位考虑它会产生的贡献,可以算出,\(p=81\times 10^{18}\)

Code

#include <bits/stdc++.h>
using namespace std;

#define Int register int
#define MAXN

template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}

#define int long long
int a,inf = 1e18;
signed main(){
	read (a);
	int p = inf % a * 9 % a * 9 % a,L = a - p,R = L + inf - 1;
	write (L),putchar (' '),write (R),putchar ('\n');
	return 0;
}
posted @ 2021-04-02 16:01  Dark_Romance  阅读(57)  评论(0编辑  收藏  举报