QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#701556#9248. An Easy Math Problem53Dawns#TL 16ms87948kbC++231.9kb2024-11-02 14:21:242024-11-02 14:21:26

Judging History

This is the latest submission verdict.

  • [2024-11-02 14:21:26]
  • Judged
  • Verdict: TL
  • Time: 16ms
  • Memory: 87948kb
  • [2024-11-02 14:21:24]
  • Submitted

answer

#include<bits/stdc++.h>
#define deg(a) cout << #a << '=' << a << "\n"
#define all(a) a.begin(),a.end()
#define lowbit(x)  ((x)&(-x))
#define find1(x)  (__builtin_popcount(x))
#define pll pair<int,int>
#define int long long
#define endl '\n'
#define ff first
#define ss second
#define ULL unsigned long long 
#define lc p << 1
#define rc p << 1|1
using namespace std;
using i64 = long long;
const int N = 1e5+10;
const int M = 1e6+10;
const int mod2 = 998244353;
const int mod1 = 1e9+7;
const int inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-12;
const int bit1 = 13331;// 底数1
const int bit2 = 13;// 底数

int f[N];

unordered_set<int>st;

void init(){
    for(int i=1;i<N;++i){
        for(int j=i;j<N;j+=i){
            f[j]++;
        }
    }

    for(int i=1;i<N;++i){
        f[i]=(f[i]+1)/2;
    }

    for(int i=2;i<N;++i){
        int x=i*i;
        st.insert(x);
        for(int j=x;j<N;j+=x){
            f[j]--;
        }
    }
}


int g(int n){
    vector<int>d;
    for(int i=1;i*i<=n;++i){
        if(n%i==0){
            d.push_back(i);
            if(n/i!=i) d.push_back(n/i);
        }
    }

    int cnt=0;
    for(auto v:d){
        if(st.count(v)) cnt++;
    }
    return (d.size()+1)/2-cnt;
}

void solve(int cases){
    int n;
    cin>>n;

    vector<int>d;
    for(int i=1;i*i<=n;++i){
        if(n%i==0){
            d.push_back(i);
            if(n/i!=i) d.push_back(n/i);
        }
    }

    int ans=0,cnt=0;
    for(auto v:d){
        if(v < N) ans += f[v];
        else{
            ans+=g(v);
        }
        if(st.count(v)) cnt++;
    }
    cout<<ans<<'\n';
}
signed main(){      
    cin.tie(nullptr); 
    ios::sync_with_stdio(false);
    int kk = 1;
    cin >> kk;
    st.reserve(1e7);
    init();
    // cin.get();
    for(int i=1;i<=kk;++i){
        solve(i);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 16ms
memory: 87948kb

input:

10
1
2
3
4
5
6
7
8
9
10

output:

1
2
2
3
2
5
2
4
3
5

result:

ok 10 lines

Test #2:

score: -100
Time Limit Exceeded

input:

2000
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
646969323...

output:


result: