QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#99967#4920. 挑战分解质因数lingchen20 7ms3492kbC++148.7kb2023-04-24 11:01:392023-04-24 11:01:42

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-24 11:01:42]
  • 评测
  • 测评结果:20
  • 用时:7ms
  • 内存:3492kb
  • [2023-04-24 11:01:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#ifndef __x86_64__
#error Only x86-64 targets are supported
#endif
#define __builtin_ia32_adc(x,y,flag) __asm__("addb   %3, %0\n\t" "adcq   %2, %1\n\t" "setc   %0":"+r"(flag),"+r"(x):"r"(y),"i"(-1):"cc")

struct bigint{// made by dengyaotriangle!
    typedef unsigned long long u64;
    typedef unsigned __int128 u128;
    typedef std::size_t st;
    std::vector<u64> data;
    bigint(){}
    bigint(u64 x):data(x?std::vector<u64>{x}:std::vector<u64>{}){}
    bigint(const std::string &s){
        st pos=s.length();
        int cnt=0;
        u64 val=0;
        while(pos){
            pos--;
            if(cnt==64){
                data.push_back(val);
                val=0;cnt=0;
            }
            val|=(u64)(s[pos]=='1')<<cnt;
            ++cnt;
        }
        if(cnt&&val)data.push_back(val);
    }
    explicit operator std::string()const{
        if(data.empty())return "0";
        bool t=0;
        std::string ret;
        for(int i=63;i>=0;i--){
            t|=(data.back()>>i)&1;
            if(t)ret+='0'|((data.back()>>i)&1);
        }
        st i=data.size()-1;
        while(i){
            i--;
            for(int j=63;j>=0;j--)ret+='0'|((data[i]>>j)&1);
        }
        return ret;
    }
    explicit operator bool()const{return !data.empty();}
    explicit operator u64()const{return data.empty()?0:data[0];}
    st digit()const{
        if(data.empty())return 0;
        return (data.size()<<6)-__builtin_clzll(data.back());
    }
    bool operator==(const bigint &a)const{return a.data==data;}
    bool operator!=(const bigint &a)const{return a.data!=data;}
    bool operator<(const bigint &a)const{
        if(data.size()!=a.data.size())return data.size()<a.data.size();
        for(st i=data.size();i;){
            i--;
            if(data[i]!=a.data[i])return data[i]<a.data[i];
        }
        return 0;
    }
    bool operator>(const bigint &a)const{return a<(*this);}
    bool operator<=(const bigint &a)const{return !(*this>a);}
    bool operator>=(const bigint &a)const{return !(*this<a);}
    bigint &operator<<=(st n){
        if(data.empty())return *this;
        int w=n&63;st z=n>>6;
        st i=data.size();
        bool flg=0;
        if(w&&(data.back()>>(64-w)))data.push_back(0),flg=1;
        data.resize(data.size()+z);
        while(i){
            i--;
            if(flg)data[i+z+1]|=data[i]>>(64-w);
            data[i+z]=data[i]<<w;
            flg|=bool(w);
        }
        for(st i=0;i<z;i++)data[i]=0;
        return *this;
    }
    bigint &operator>>=(st n){
        int w=n&63;st z=n>>6,i=0;
        for(;i+z<data.size();i++){
            if(w&&i)data[i-1]|=data[i+z]<<(64-w);
            data[i]=data[i+z]>>w;
        }
        while(data.size()>i)data.pop_back();
        while(!data.empty()&&data.back()==0)data.pop_back();
        return *this;
    }
    bigint operator<<(st n)const{return bigint(*this)<<=n;}
    bigint operator>>(st n)const{return bigint(*this)>>=n;}
    bigint &operator+=(const bigint &a){
        data.resize(std::max(data.size(),a.data.size()));
        bool carry=0;
        for(st i=0;i<data.size();i++){
            u64 rg=0;
            if(i<a.data.size())rg=a.data[i];
            __builtin_ia32_adc(data[i],rg,carry);
        }
        if(carry)data.push_back(1);
        return *this;
    }
    bigint &operator-=(const bigint &a){
        bool carry=1;
        for(st i=0;i<data.size();i++){
            u64 rg=-1;
            if(i<a.data.size())rg=~a.data[i];
            __builtin_ia32_adc(data[i],rg,carry);
        }
        while(!data.empty()&&data.back()==0)data.pop_back();
        return *this;
    }
    bigint &operator++(){return *this+=bigint(1);}
    bigint &operator--(){return *this-=bigint(1);}
    bigint operator++(int){bigint tmp=*this;++*this;return tmp;}
    bigint operator--(int){bigint tmp=*this;--*this;return tmp;}
    bigint &operator*=(const bigint &a){
        std::vector<u64> ret(data.size()+a.data.size());
        for(st i=0;i<data.size();i++){
            u64 carry=0;bool wcarry=0;
            st k=i;
            for(st j=0;j<a.data.size();j++,k++){
                u128 r=data[i]*(u128)a.data[j]+carry;
                u64 cur=r;
                carry=r>>64;
                __builtin_ia32_adc(ret[k],cur,wcarry);
            }
            while(carry||wcarry){
                __builtin_ia32_adc(ret[k],carry,wcarry);
                carry=0;k++;
            }
        }
        while(!ret.empty()&&ret.back()==0)ret.pop_back();
        data=ret;
        return *this;
    }
    bigint &operator/=(const bigint &a){
        if(a.digit()>digit()){
            data.clear();
            return *this;
        }
        st z=digit()-a.digit();
        std::vector<u64> ret;
        while(1){
            bigint tmp=a<<z;
            if(tmp<=*this){
                *this-=tmp;
                st v1=z>>6;
                if(ret.size()<=v1)ret.resize(v1+1);
                ret[v1]|=(u64)(1)<<(z&63);
            }
            if(!z)break;
            z--;
        }
        data=ret;
        return *this;
    }
    bigint &operator%=(const bigint &a){
        if(a.digit()>digit())return *this;
        st z=digit()-a.digit();
        while(1){
            bigint tmp=a<<z;
            if(tmp<=*this)*this-=tmp;
            if(!z)break;
            z--;
        }
        return *this;
    }
    bigint operator+(const bigint &a)const{return bigint(*this)+=a;}
    bigint operator-(const bigint &a)const{return bigint(*this)-=a;}
    bigint operator*(const bigint &a)const{return bigint(*this)*=a;}
    bigint operator/(const bigint &a)const{return bigint(*this)/=a;}
    bigint operator%(const bigint &a)const{return bigint(*this)%=a;}
};
std::istream &operator>>(std::istream &st,bigint &a){
    std::string s;st>>s;a=bigint(s);return st;
}
std::ostream &operator<<(std::ostream &st,const bigint &a){
    return st<<(std::string)(a);
}

typedef long long ll;
typedef __int128 lll;
const ll prime[7] = {2,325,9375,28178,450775,9780504,1795265022};

bigint n,phi;

namespace Sub1 {
    vector<long long> v;
    void print(ll x) { if(!x) return; print(x>>1); putchar('0'+(x&1)); }
    void work()
    {
        ll n=(unsigned long long)(::n);
        
        for(lll i=2; i*i<=n; i++)
        if(n%i==0)
        {
            while(n%i==0)
            n/=i, v.push_back(i);
        }
        if(n!=1) v.push_back(n);
        cout<<v.size()<<"\n";
        for(ll x : v)
        print(x), putchar('\n');
    }
}
namespace Sub2 {
    mt19937_64 mt;

    lll abs(lll x) { return x>0 ? x : -x; }
    lll qpow(lll a, lll b, lll p)
    {
        lll ans=1;
        for(; b; b>>=1,(a*=a)%=p)
        if(b&1) (ans*=a)%=p;
        return ans;
    }
    bool millerRabin(lll n)
    {
        if(n==1) return 0;
        if(n%2==0) return n==2;

        lll u=n-1,t=0;
        while(u%2==0) u>>=1,++t;
        for(lll a : prime)
        {
            lll b=qpow(a, u, n);
            if(b==1||b==n-1||b==0) continue;
            for(int i=1; i<=t; i++)
            {
                b=b*b%n;
                if(b==n-1) {b=1; break;}
                else if(b==1) return 0;
            }
            if(b!=1) return 0;
        }
        return 1;
    }
    lll pollardRho(lll n)
    {
        lll s=0,t=0,c=mt()%(n-1)+1;
        for(int i=1;; i<<=1,s=t)
        {
            lll val=1;
            for(int j=1; j<=i; j++)
            {
                t=(t*t+c)%n;
                val=val*abs((lll)(t-s))%n;
                if(j%127==0)
                {
                    lll g=__gcd(val, (lll)n);
                    if(g!=1) return g;
                }
            }
            lll g=__gcd(val, (lll)n);
            if(g!=1) return g;
        }
        return 0;
    }
    vector<lll> calc(lll x)
    {
        vector<lll> v;
        if(x==1) return v;
        if(millerRabin(x))
        {
            v.push_back(x);
            return v;
        }
        lll p=x,t=0;
        while(p==x) p=pollardRho(x);
        while(x%p==0) x/=p,t++;
        v=calc(x);
        vector<lll> b=calc(p);
        for(lll e : b)
        for(int i=1; i<=t; i++)
        v.push_back(e);
        return v;
    }
    void print(lll x) { if(!x) return; print(x>>1); putchar('0'+(x&1)); }
    void work()
    {
        vector<lll> v=calc((unsigned long long)(n));
        sort(v.begin(), v.end());
        cout<<v.size()<<"\n";
        for(lll x : v)
        print(x), putchar('\n');
    }
}
int main()
{
    cin>>n>>phi;
    if(n.digit()<=32) Sub1::work();
    else if(n.digit()<=64) Sub2::work();
    return 0;
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 2ms
memory: 3348kb

input:

1 1

output:

0

result:

ok "0"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3492kb

input:

1000001010000010011000000000001 1000001010000000000000000000000

output:

2
100100000000001
1110100000000001

result:

ok 3 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 3388kb

input:

100011100111101010100110101011 100011100111011001010101000000

output:

2
10011001001011
1110111000100001

result:

ok 3 tokens

Test #4:

score: 0
Accepted
time: 2ms
memory: 3420kb

input:

10001001101010010000101100001111 10001001101001111001001011011000

output:

2
1011000000011011
1100100000011101

result:

ok 3 tokens

Test #5:

score: 0
Accepted
time: 0ms
memory: 3416kb

input:

11010101110001001000101110100011 10001110011111110101111001100000

output:

4
11
11
100100101110011
101001011001001

result:

ok 5 tokens

Test #6:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

11110110100011100110011001 11110100100110011000000000

output:

3
100010101
101100001
1010010101

result:

ok 4 tokens

Test #7:

score: 0
Accepted
time: 2ms
memory: 3340kb

input:

11111101101000100101001011110000 1111110001100110011100011000000

output:

7
10
10
10
10
110111011
1010010011
1110001111

result:

ok 8 tokens

Test #8:

score: 0
Accepted
time: 2ms
memory: 3444kb

input:

10000000000000000000000000000000 1000000000000000000000000000000

output:

31
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10

result:

ok 32 tokens

Test #9:

score: 0
Accepted
time: 0ms
memory: 3372kb

input:

10100000001100011011100000000000 100010110011100000000000000000

output:

17
10
10
10
10
10
10
10
10
10
10
10
11
111
1011
1101
10011
10111

result:

ok 18 tokens

Test #10:

score: 0
Accepted
time: 0ms
memory: 3388kb

input:

10100010000000000000000000000001 10100010000000000000000000000000

output:

1
10100010000000000000000000000001

result:

ok 2 tokens

Test #11:

score: 0
Accepted
time: 0ms
memory: 3384kb

input:

11011011011011001101111101010000 101101100110000011101000000000

output:

9
10
10
10
10
11
101
111
1011
110000101000100111

result:

ok 10 tokens

Test #12:

score: 0
Accepted
time: 1ms
memory: 3344kb

input:

110000101111111000100000001 110000101111100100110000010

output:

2
10011101111111
10011101111111

result:

ok 3 tokens

Test #13:

score: 0
Accepted
time: 2ms
memory: 3384kb

input:

110011010101010011110001 100000011111011111100000

output:

8
101
101
101
111
111
1101
1101
1101

result:

ok 9 tokens

Test #14:

score: 0
Accepted
time: 1ms
memory: 3480kb

input:

100001110101100001111101110111 100000100101110000010111000000

output:

4
11101
11101
1011111001
1101110111

result:

ok 5 tokens

Test #15:

score: 0
Accepted
time: 0ms
memory: 3388kb

input:

110111000001001110000000001111 110100101000000111101101001100

output:

3
10111
10111
110101010000000011111

result:

ok 4 tokens

Subtask #2:

score: 15
Accepted

Dependency #1:

100%
Accepted

Test #16:

score: 15
Accepted
time: 0ms
memory: 3388kb

input:

10100111000100000000000000000011100100000000000000000000000001 10100111000100000000000000000000000000000000000000000000000000

output:

2
1000010000000000000000000000001
10100010000000000000000000000001

result:

ok 3 tokens

Test #17:

score: 0
Accepted
time: 7ms
memory: 3352kb

input:

1000010000111101001111000011011101001000011011101010000010110001 1000010000111101001111000011010111010111011001001101011101100100

output:

2
10101010100101101001100101011111
11000110011100110010111111101111

result:

ok 3 tokens

Test #18:

score: 0
Accepted
time: 4ms
memory: 3352kb

input:

1001011100010111001100011001111111010011001111110111011010111001 1001011100010111001100011001111001000110010111101110000111110100

output:

2
10101100000000010111100000001111
11100000110111110001110010110111

result:

ok 3 tokens

Test #19:

score: 0
Accepted
time: 5ms
memory: 3420kb

input:

1100100001100010110111100100101001111000010010100011110010110000 110010000110001011011110010000000010001001010011111110000000000

output:

6
10
10
10
10
10110011011100000011110001011
10001110111100010101110011000001

result:

ok 7 tokens

Test #20:

score: 0
Accepted
time: 1ms
memory: 3352kb

input:

1010101001010100010010001101000111000100010110010111111001100000 101010100101010000011000100110001101001011001011011000000000000

output:

8
10
10
10
10
10
10001010110010000101
10010001100100110111
100010100010000100001

result:

ok 9 tokens

Test #21:

score: 0
Accepted
time: 1ms
memory: 3476kb

input:

1011000100010101011000101010110000001001011100000000000001 1011000100010101000000000000000000000000000000000000000000

output:

3
100100000000000001
100010100000000000001
100100100000000000001

result:

ok 4 tokens

Test #22:

score: 0
Accepted
time: 0ms
memory: 3436kb

input:

101110011111000001101010111000000000111001000000000000001 101110011111000000000000000000000000000000000000000000000

output:

3
101000000000000001
10001000000000000001
100011000000000000001

result:

ok 4 tokens

Test #23:

score: 0
Accepted
time: 2ms
memory: 3344kb

input:

1000000000000000000000000000000000000000000000000000000000000000 100000000000000000000000000000000000000000000000000000000000000

output:

63
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10

result:

ok 64 tokens

Test #24:

score: 0
Accepted
time: 2ms
memory: 3432kb

input:

11110011110101111001001011010001111000011100110110000000001 11110011110101111001001011001100010111000111010001000000010

output:

2
101100001010101100100111111111
101100001010101100100111111111

result:

ok 3 tokens

Test #25:

score: 0
Accepted
time: 2ms
memory: 3348kb

input:

100001011001100001110000001100100000000110000000110001 11010001011110111111001000110100010000000000000000000

output:

10
111
111
111
10011
10011
10011
11101
11101
11101
101000000000000001

result:

ok 11 tokens

Test #26:

score: 0
Accepted
time: 2ms
memory: 3436kb

input:

110101111011111001001010000111000010010000101101100011010111 110101111011010011000110101000011001001010110111110000000000

output:

4
10010001111111
1001011010011101
1010010111011101
1111100000100001

result:

ok 5 tokens

Test #27:

score: 0
Accepted
time: 2ms
memory: 3456kb

input:

1111010001111011110110111110111110010010011100001000000000000000 111000110100111001111001110001101101010110101000000000000000000

output:

24
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
11111
11111
11111
101011
101011
101011
111101
111101
111101

result:

ok 25 tokens

Test #28:

score: 0
Accepted
time: 5ms
memory: 3428kb

input:

1001000010000000000000000000001000100000000000000000000000000010 100100001000000000000000000000010001000000000000000000000000000

output:

3
10
10001000000000000000000000000001
10001000000000000000000000000001

result:

ok 4 tokens

Test #29:

score: 0
Accepted
time: 2ms
memory: 3304kb

input:

11110011111110001110100010001010000001100000011000111 10100011001000011100000101000000110000000000000000000

output:

10
111
1101
10011
101001
101111
110101
1000111
1001001
1010011
1110001

result:

ok 11 tokens

Test #30:

score: 0
Accepted
time: 2ms
memory: 3316kb

input:

100100000100001011001110111001100101010011010110010101 100010110110100001110110011010000010001110111110000000

output:

8
111101
111101
1011001
1011001
1011001
10011101
10011101
10011101

result:

ok 9 tokens

Subtask #3:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 2ms
memory: 3332kb

input:

100001100011000011110101000011010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010011101101001101100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 10000...

output:


result:

wrong answer Unexpected EOF in the participants output

Subtask #4:

score: 0
Wrong Answer

Test #46:

score: 0
Wrong Answer
time: 2ms
memory: 3448kb

input:

11011110000000000010100100101011111000100001100010011001110111010100101110110011111101111100001110110100010000000001111000110000100110111011000111000111001010000001010111010001111111000111100110011010111001011011010001100010101001001111111101000110011110011101011100000001101110111011000101010101101 ...

output:


result:

wrong answer Unexpected EOF in the participants output

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #6:

0%