传送门
文章目录
- 题意:
- 思路:
题意:
定义f(x)f(x)f(x)表示xxx的十进制下数位和,现在给你aaa,让你选一个区间[l,r][l,r][l,r],满足∑i=lrf(i)moda=0\sum_{i=l}^rf(i)\bmod a=0∑i=lrf(i)moda=0。
1≤a≤1e181\le a\le1e181≤a≤1e18
要求输出的l,rl,rl,r满足1≤l≤r≤102001\le l\le r\le 10^{200}1≤l≤r≤10200
思路:
考虑这样一个事情,对于xxx,我们找一个10k>x10^k>x10k>x,那么此时f(10k+x)−f(x)=1f(10^k+x)-f(x)=1f(10k+x)−f(x)=1。
有了这个之后,我们自然的想构造出来aaa个这样的对,这样模aaa就是000了。
取一个比aaa大的101010的幂次101910^{19}1019,所以就会想到构造这样的区间[a+1,1019+a][a+1,10^{19}+a][a+1,1019+a],转换成前缀和的形式[1,1019+a]−[1,a][1,10^{19}+a]-[1,a][1,1019+a]−[1,a],显然这是不行的,虽然这样保证了[1,a],[1019+1,1019+a][1,a],[10^{19}+1,10^{19}+a][1,a],[1019+1,1019+a]两个区间对应数fff做差为111,并且有aaa个这样的数,但是忽略了[a+1,1019][a+1,10^{19}][a+1,1019]这段区间对答案的贡献,那么既然去不掉这段区间,那么不妨将这段区间加入答案中,也就是我们上面说的aaa对这样的数,假设多出来kkk,那么我们只需要添加a−ka-ka−k对即可,考虑这些多出来的怎么计算。
我们考虑求出来∑i=11019f(i)moda\sum_{i=1}^{10^{19}}f(i)\bmod a∑i=11019f(i)moda,设其为kkk,换句话说,我们现在需要加上a−ka-ka−k个111就可以达到要求了。考虑将原本区间[1,1019][1,10^{19}][1,1019]不断右移,比如右移一次[2,1019+1][2,10^{19}+1][2,1019+1],不难发现,这个时候原本的111的贡献变成了1+10191+10^{19}1+1019的贡献,增加了111,所以我们右移a−ka-ka−k次,得到区间[a−k+1,1019+a−k][a-k+1,10^{19}+a-k][a−k+1,1019+a−k],答案就是这个区间啦。
取一个比较大的101010的幂次,防止移动过程中超过这个幂次即可。
// Problem: C. Hack it!
// Contest: Codeforces - Codeforces Round #268 (Div. 1)
// URL: https://codeforces.com/problemset/problem/468/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,INF=0x3f3f3f3f;
const double eps=1e-6;LL f[30][10*20],mod;
int a[30];LL dp(int pos,LL sum,int flag) {if(pos==0) return sum%mod;if(f[pos][sum]!=-1&&flag) return f[pos][sum];int x=flag? 9:a[pos];LL ans=0;for(int i=0;i<=x;i++) (ans+=dp(pos-1,sum+i,flag||i<x))%=mod;if(flag) f[pos][sum]=ans;return ans;
}LL solve() {// int tot=0;// while(x) a[++tot]=x%10,x/=10;// return dp(tot,0,0);for(int i=1;i<=19;i++) a[i]=0;a[20]=1;return dp(20,0,0);
}inline __int128 read()
{__int128 x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}inline void write(__int128 x)
{if(x<0){putchar('-');x=-x;}if(x>9)write(x/10);putchar(x%10+'0');
}int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);memset(f,-1,sizeof(f));scanf("%lld",&mod);LL k=solve()%mod;write((__int128)mod-k+1); putchar(' ');write((__int128)100000000000000000*100+mod-k);puts("");return 0;
}
/**/