sb码风求调
查看原帖
sb码风求调
311306
dk_qwq楼主2023/2/20 17:38

RT

#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
namespace INPUT{
    char buf[1<<20],*p1,*p2;
    #define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
}
using namespace INPUT;
template<typename T>
inline T read(){
    T x=0,p=1;
    char ch=gc();
    for(;ch<'0'||ch>'9';ch=gc())
        if(ch=='-') p=-1;
    for(;ch>='0'&&ch<='9';ch=gc())
        x=(x<<3)+(x<<1)+(ch^48);
    return x*p;
}
#include<algorithm>
const int N=1e4+5;
#define ll long long
#define mod (ll)(1e9)
int n,m;
ll x,a[N],b[N];
int al,bl;
ll ans=1;
int main(){
    // freopen("SP18202.in","r",stdin);
    // freopen("SP18202.out","w",stdout);
    n=read<int>();
    for(int i=1;i<=n;i++){
        x=read<ll>();
        for(ll k=2;k<=x;k++)
            while(x%k==0&&k<=x) a[++al]=k,x/=k;
    }
    m=read<int>();
    for(int i=1;i<=m;i++){
        x=read<ll>();
        for(ll k=2;k<=x;k++)
            while(x%k==0&&k<=x) b[++bl]=k,x/=k;
    }
    sort(a+1,a+1+al),sort(b+1,b+1+bl);
    int l1=1,l2=1;
    bool B=false;
    while(l1<=al&&l2<=bl){
        if(a[l1]==b[l2]){
            if(ans*a[l1]>=mod) B=true;
            ans=(ans*a[l1])%mod;
            l1++,l2++;
        }
        if(a[l1]<b[l2]) l1++;
        if(a[l1]>b[l2]) l2++;
    }
    if(B) printf("%09lld",ans);
    else printf("%lld",ans);
}
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
namespace INPUT{
    char buf[1<<20],*p1,*p2;
    #define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
}
using namespace INPUT;
template<typename T>
inline T read(){
    T x=0,p=1;
    char ch=gc();
    for(;ch<'0'||ch>'9';ch=gc())
        if(ch=='-') p=-1;
    for(;ch>='0'&&ch<='9';ch=gc())
        x=(x<<3)+(x<<1)+(ch^48);
    return x*p;
}
const int N=1e4+5;
#define ll long long
#define mod (ll)(1e9)
int n,m;
ll x,ans=1;
bool B=false;
ll pow(ll x,ll k){
	ll ans=1;
	while(k){
		if(k&1){
			if(ans*x>=mod) B=true;
			ans=(ans*x)%mod;
		}
		if(k&&x*x>=mod) B=true;
		x=(x*x)%mod;
		k>>=1;
	}
	return ans;
}
#include<map>
map<int,int>M;
int main(){
    // freopen("SP18202.in","r",stdin);
    // freopen("SP18202.out","w",stdout);
    n=read<int>();
    for(int i=1;i<=n;i++){
        x=read<ll>();
        for(ll k=2;k<=x;k++){
			if(x%k) continue;
			int cnt=0;
			while(x%k==0&&k<=x) cnt++,x/=k;
			M[k]+=cnt;
		}
    }
    m=read<int>();
    for(int i=1;i<=m;i++){
        x=read<ll>();
        for(ll k=2;k<=x;k++){
			if(x%k) continue;
			int cnt=0,h=M[k];
            while(x%k==0&&k<=x) {
				if(cnt<h) cnt++;
				x/=k;
			}
			M[k]-=cnt;
			ll mul=pow(k,cnt);
			if(ans*mul>=mod) B=true;
			ans=(ans*mul)%mod;
		}
		
    }
    if(B) printf("%09lld",ans);
    else printf("%lld",ans);
	return 0;
}

想知道为什么两份代码都TLE了

2023/2/20 17:38
加载中...