NOIP2018原创模拟赛DAY1 小凯的数字

题目描述:
大概是给定两个数,l,r

组整一个新的数字,每个数位是从l到r

例如l=2,r=4

组成的数字就是234

然后就是开开心心的小学奥数时间(划不掉的悲伤)

考完了之后发现T1只有70分,不应该呀,然后一练么懵逼的看了正解,卡了long long

(后来发现unsigned long long 也过不了)(mdzz)

让我回想起了在hzwer的模考中被卡了int的经历(一道题全TM给卡没了)

总之原来的每个数位相加是大家都知道的(假装都知道)

然后我们来想,九这个模数是比较奇特的,因为9*10^n后余数是不会变的,所以不用按位取数,直接相加后在取模就可以了

具体不太好证,考场上魔改出来的,发现卡不掉

具体证明过程去出题人博客看吧:
https://blog.csdn.net/Hi_KER/article/details/82782098

心态就很崩溃(QAQ)

下面给出代码:(注释就算了,毕竟没有操作难度)

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
inline unsigned long long rd()
{
    unsigned long long x=0,f=1;
    char c=getchar();
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return x*f;
}
inline void write(unsigned long long x)
{
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
unsigned long long n; 
unsigned long long l,r,ans;
int main()
{
    n=rd();
    while(n--){
        l=rd();
        r=rd();
        unsigned long long x=r-l+1;
        unsigned long long y=r+l;
        if(x%2==0) x/=2;
        if(y%2==0) y/=2;
        ans=((x%9)*(y%9))%9;
        write(ans);
        puts("");
    }
    return 0;
}

 

posted @ 2018-09-24 19:27  Bruce--Wang  阅读(290)  评论(0编辑  收藏  举报