把博客园图标替换成自己的图标
把博客园图标替换成自己的图标end

【CF468C】Hack it!(构造)

点此看题面

  • 定义\(f(x)\)为一个十进制数\(x\)所有数码的和。
  • 给定\(a\),求构造一对\(l,r(l\le r)\),满足\(\sum_{i=l}^rf(i)\equiv0(mod\ a)\)
  • \(1\le a\le10^{18}\)

构造

考虑对于任意\(x<10^{18}\),都有\(f(x+10^{18})=f(x)+1\)(应该是显然,就相当于在开头添了一个\(1\))。

所以说,如果我们能求出\(\sum_{i=0}^{10^{18}-1}f(i)\equiv t(mod\ a)\),那么只要给它左右端点同时加上\(a-t\),根据之前的结论就能使得左式的值恰好加上\(a-t\)

因此,构造出的\(\sum_{i=a-t}^{10^{18}-1+a-t}f(i)\equiv0(mod\ a)\)

而要求\(t\)是非常简单的,就是考虑每一位共有\(9\)种选法,总和为\(45\),而位与位之间的选择独立,因此每一位的每种选法都能出现\(10^{17}\)次。

综上,我们有:

\[\sum_{i=0}^{10^{18}-1}=18\times 45\times10^{17}=81\times10^{18} \]

所以这道题就做完了。

代码:\(O(1)\)

#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define LL long long
using namespace std;
int main()
{
	LL a;scanf("%lld",&a);LL x=(LL)1e18,y=x*9%a*9%a;return printf("%lld %lld\n",a-y,x-1+a-y),0;//直接构造
}
posted @ 2021-03-30 11:16  TheLostWeak  阅读(75)  评论(0编辑  收藏  举报