QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561881#9248. An Easy Math Problemucup-team1766AC ✓6ms3740kbC++201.7kb2024-09-13 11:55:212024-09-13 11:55:22

Judging History

你现在查看的是测评时间为 2024-09-13 11:55:22 的历史记录

  • [2024-10-31 22:40:27]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:6ms
  • 内存:3972kb
  • [2024-10-31 22:36:43]
  • hack成功,自动添加数据
  • (/hack/1098)
  • [2024-10-31 22:17:36]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:6ms
  • 内存:3932kb
  • [2024-10-31 22:13:58]
  • hack成功,自动添加数据
  • (/hack/1096)
  • [2024-10-31 22:06:41]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:6ms
  • 内存:3892kb
  • [2024-10-31 22:00:43]
  • hack成功,自动添加数据
  • (/hack/1095)
  • [2024-09-13 11:55:22]
  • 评测
  • 测评结果:100
  • 用时:6ms
  • 内存:3740kb
  • [2024-09-13 11:55:21]
  • 提交

answer

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

// Function to generate all prime numbers up to n using Sieve of Eratosthenes
vector<int> sieve(int n) {
    vector<bool> is_prime(n+1, true);
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i*i <=n; ++i){
        if(is_prime[i]){
            for(int j=i*i; j<=n; j+=i){
                is_prime[j] = false;
            }
        }
    }
    vector<int> primes;
    for(int i=2; i<=n; ++i){
        if(is_prime[i]) primes.push_back(i);
    }
    return primes;
}

// Function to factorize n using the list of primes
vector<pair<ll, int>> factorize(ll n, const vector<int>& primes){
    vector<pair<ll, int>> factors;
    for(auto p : primes){
        if((ll)p * p > n) break;
        if(n % p == 0){
            int count =0;
            while(n % p ==0){
                count++;
                n /= p;
            }
            factors.emplace_back(make_pair((ll)p, count));
        }
    }
    if(n >1){
        factors.emplace_back(make_pair(n,1));
    }
    return factors;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    // Precompute primes up to 100,000
    vector<int> primes = sieve(100000);
    
    int q;
    cin >> q;
    while(q--){
        ll n;
        cin >> n;
        if(n ==0){
            cout << "0\n";
            continue;
        }
        // Factorize n
        vector<pair<ll, int>> factors = factorize(n, primes);
        // Calculate the product of (2*e_i +1)
        ll total =1;
        for(auto &[prime, exp] : factors){
            total *= (2LL * exp +1);
        }
        // Calculate (total +1)/2
        ll answer = (total +1)/2;
        cout << answer << "\n";
    }
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3648kb

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: 0
Accepted
time: 1ms
memory: 3740kb

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:

29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
...

result:

ok 2000 lines

Test #3:

score: 0
Accepted
time: 6ms
memory: 3688kb

input:

2000
1763047095
79735483
1016286871
2864801397
2327774116
2668010360
3469893354
3634459021
1613699068
781737219
574741575
2763134701
1458502604
1822260248
2281150332
2924219311
2493931196
3735904708
158802001
2006921221
729928782
1974841034
727412600
2873393292
1291087179
2741607663
1893408215
29827...

output:

14
5
2
5
23
95
68
14
8
68
203
14
23
32
38
41
8
8
14
2
608
41
158
338
23
41
14
5
14
41
14
203
41
14
17
446
5
53
59
878
2
14
365
203
14
203
2
122
32
95
41
41
5
23
14
41
5
5
14
122
23
203
608
23
41
122
2
14
95
2
68
41
203
14
230
41
68
23
50
14
32
14
8
5
5
5
68
68
122
293
473
5
41
41
14
2
14
14
5
2
122
...

result:

ok 2000 lines

Extra Test:

score: 0
Extra Test Passed