/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 336.0 KiB
#3 Accepted 1ms 540.0 KiB
#4 Accepted 1ms 392.0 KiB
#5 Accepted 1ms 516.0 KiB
#6 Accepted 3ms 584.0 KiB
#7 Accepted 4ms 596.0 KiB
#8 Accepted 5ms 580.0 KiB
#9 Accepted 5ms 496.0 KiB
#10 Accepted 5ms 576.0 KiB
#11 Accepted 4ms 572.0 KiB
#12 Accepted 4ms 588.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=2e5+10,MOD=2000000007;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
    map<int,int>one,two,three;
    ll x;
    set<int>st;
    vector<int>v;
    one[1]++;
    two[1]++;
    three[1]++;
    for(int i=1;i<=3;i++){
        int a;
        cin>>a;
        v.push_back(a);
    }
    cin>>x;
    int cur=1;
    for(int i:v){
       ll d=i;
       for(ll j=2;j*j<=d;j++){
           if(d%j==0){
            st.insert(j);
            while(d%j==0 && d>1){
                d/=j;
                if(cur==1)one[j]++;
                if(cur==2)two[j]++;
                if(cur==3)three[j]++;
            }
           }
       }
       if(d>1){
        st.insert(d);
         if(cur==1)one[d]++;
                if(cur==2)two[d]++;
                if(cur==3)three[d]++;
       }
       cur++;
    }
    ll res=1;
    for(auto it:st){
      ll i=it;
      int mx=max({one[it],two[it],three[it]});
      while(mx>0){
        if(res*i>=x){
            res=-1;
            break;
        }
        res*=i;
        mx--;
      }
      if(res==-1)break;
    }
    if(res!=-1){
        ll d=x/res;
        if(x%res==0)d--;
        res*=d;
    }
    cout<<res<<"\n";



    
   }
   return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1025 GCM
Contest
Brain booster #2
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-06 16:43:14
Judged At
2024-03-06 16:43:14
Judged By
Score
100
Total Time
5ms
Peak Memory
596.0 KiB