CF468C
Hack it!
非常思维的一道构造题。
考验了乱搞的能力。。。
我们发现这个
比如说,我们取
原因就是,我们同时加的时候较低位的数字被抵消了,只有最高位的数字做出了贡献。然而此时的最高位就是 1,那么加上了
然后就是直接乱搞了。
因为这里的
时间复杂度
更为神奇的方法是直接把极限调在
但是同样为了防止溢出,我们的一般运算是通过两次乘 9 来实现的。
代码:
#include<iostream>
#include<cstdio>
#define ll __int128
using namespace std;
ll a,b,p,l,sum,ans,pos;
ll aa[105];
inline ll read() {
ll ret=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-f;ch=getchar();}
while(ch>='0'&&ch<='9') {ret=(ret<<3)+(ret<<1)+ch-'0';ch=getchar();}
return ret*f;
}
void write(ll x) {
static char buf[22];static ll len=-1;
if(x>=0) {
do{buf[++len]=x%10+48;x/=10;}while(x);
}
else {
putchar('-');
do{buf[++len]=x%10+48;x/=10;}while(x);
}
while(len>=0) putchar(buf[len--]);
}
int main() {
a=read();
b=10;p=101;ans=1;
while(p>0) {
if(p&1) ans=(ans*b)%a;
b=(b*b)%a;p>>=1;
}
for(ll i=1;i<=9;i++) {
sum=(sum+ans*i%a)%a;
}
l=a-sum;
write(l);putchar(' ');
aa[1]=1;l--;pos=101;
while(l>0) {
aa[pos--]=l%10;l/=10;
}
for(ll i=1;i<=101;i++) {
write(aa[i]);
}
return 0;
}
代码:(
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
const ll lim=1e18;
ll a,l,r;
inline ll read() {
ll ret=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-f;ch=getchar();}
while(ch>='0'&&ch<='9') {ret=(ret<<3)+(ret<<1)+ch-'0';ch=getchar();}
return ret*f;
}
void write(ll x) {
static char buf[22];static ll len=-1;
if(x>=0) {
do{buf[++len]=x%10+48;x/=10;}while(x);
}
else {
putchar('-');
do{buf[++len]=x%10+48;x/=10;}while(x);
}
while(len>=0) putchar(buf[len--]);
}
int main() {
a=read();
l=a-lim%a*9%a*9%a;
r=lim-1+l;
write(l);putchar(' ');write(r);
return 0;
}