2018QBXT刷题游记(1)

【2018QBXT刷题游记】

Day1 TEST1
T1

【题目大意】输入n,求n与\(246913578\)的最小公倍数,对1234567890取模

对于 30%的数据, \(n<=10^{9}\)
对于 60%的数据,\(n<=10^{18}\)
对于 100%的数据,\(n<=10^{100000}\)

【慌乱分析】这是个什么鬼数??又是什么鬼数据范围???
当我敲出const int qaq=246913578;时,好像突然意识到了什么?1到9各出现了一次啊,一定有蹊跷!于是求了一下它的因数:

1409044-20181103184244944-474176593.png

妙啊!123456789!
也就是说它是1234567890的1/5,所以只用求输入的n%5余数就好啦(考场想法,70分w)

于是得到了70分的...好成绩...(QAQ)
下面是冗长丑陋的代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
#define ll long long
ll qwq[35],qaq[35],f1[35],f2[35];
void init(){
    qwq[1]=2;qwq[2]=3;qwq[3]=6;qwq[4]=9;qwq[5]=18;
    qwq[6]=3607;qwq[7]=3803;qwq[8]=7214;qwq[9]=7606;
    qwq[10]=10821;qwq[11]=11409;qwq[12]=21642;
    qwq[13]=22818;qwq[14]=32463;
    qwq[15]=34227;qwq[16]=64926;qwq[17]=68454;
    qwq[18]=13717421;qwq[19]=27434842;
    qwq[20]=41152263;qwq[21]=82304526;
    qwq[22]=123456789;qwq[23]=246913578;
    for(int i=1;i<=22;i++)qaq[i]=qwq[23-i];
    qaq[23]=1;
}
ll n;
int emm=246913578;
#define MOD 12345678
int main(){
    freopen("lcm.in","r",stdin);
    freopen("lcm.out","w",stdout);
    init();
    cin>>n;
    if(n<emm){
        ll tmp=0;ll q;
        for(int i=22;i>=1;i--){
            if(n%qwq[i]==0){
                tmp=n/qwq[i];
                q=qwq[i];
                break;
            }
        }
        if(tmp){
            int f=tmp%5;
            cout<<emm*f<<endl;
            return 0;
        }
        else{
            int f=n%5;
            cout<<emm*f<<endl;
            return 0;
        }
    }
    if(n==emm){
        cout<<emm<<endl;
            return 0;
    }
    if(n>emm){
        ll tmp=0;ll q;
        for(int i=22;i>=1;i--){
            if(n%qwq[i]==0){
                tmp=n/qwq[i];
                q=qwq[i];
                break;
            }
        }
        if(tmp){
            int f=tmp%5;
            cout<<emm*f<<endl;
            return 0;
        }
        else{
            int f=n%5;
            cout<<emm*f<<endl;
            return 0;
        }
    }   
    return 0;
}

当看到解析的时候我是忧伤的...
啊...要是推一推公式就100了...

输入高精度数a与普通整数b求lcm,对c取模,c是b的倍数“”

\(lcm(x, y) = \frac{xy}{gcd(x,y)}\)

\(gcd(x, y)=gcd(x − y, y)\)

可知 \(lcm(a, b) =\frac{ab}{gcd(a\mod b,\ b)}\)

由于c是b的倍数 \(lcm(a,b)=\frac{ab}{gcd(a\mod c,\ b)}\)

$lcm(a,b)\equiv \frac {(a mod c)b}{gcd((a\mod c),b)}(mod  c) $

所以可以边输入边取模,不涉及高精问题了!

修改版代码

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
const int MOD=1234567890;
const int qaq=246913578;
ll gcd(ll x,ll y){
    if(y==0)return x;
    else return gcd(y,x%y);
} 
int main(){
    char t;
    t=getchar();
    ll n;
    while(t>='0'&&t<='9'){
        n=(n*10+t-'0')%MOD;//边读入边取模,学到了
        t=getchar();
    }
    n=n/gcd(n,246913578);
    n=n*qaq%MOD;
    cout<<n<<endl;
    return 0;
}

转载于:https://www.cnblogs.com/erutsiom/p/9901688.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值