Skip to content

Commit fb33b57

Browse files
committed
srm 643 div 2 500 sol
1 parent daffbca commit fb33b57

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

TheKingsFactorization.cpp

+26-19
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,39 @@ typedef long long ll;
2020
class TheKingsFactorization{
2121
public:
2222

23-
vector<long long> getVector(long long N, vector<long long> primes) {
24-
23+
vector<ll> getVector(long long N, vector<long long> primes) {
24+
int m = primes.size();
2525
vector<ll> res;
26-
27-
for(ll p : primes){
28-
res.push_back(p);
29-
N /= p;
30-
if(N%p == 0){
31-
N /= p;
32-
res.push_back(p);
33-
}
26+
res.push_back(primes[0]);
27+
28+
if(m == 1){
29+
if(N != primes[0]){
30+
res.push_back(N/primes[0]);
31+
return res;
32+
}
33+
return res;
3434
}
35-
36-
for(int k = 3; k <= 1000000; k += 2){
37-
if(N%k == 0)
38-
while(N%k == 0){
39-
res.push_back(k);
40-
N /= k;
41-
}
35+
for(int i = 0; i+1 < m; i++){
36+
ll p0 = primes[i], p1 = primes[i+1];
37+
N /= p0;
38+
for(ll p = p0; p <= p1; p++)
39+
if(N%p == 0){
40+
res.push_back(p);
41+
N /= p;
42+
p = p1+1;
43+
}
44+
res.push_back(p1);
4245
}
43-
46+
47+
N /= primes[m-1];
48+
4449
if(N > 1) res.push_back(N);
45-
sort(res.begin(), res.end());
50+
4651
return res;
4752
}
4853

54+
55+
4956
// BEGIN CUT HERE
5057
public:
5158
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); if ((Case == -1) || (Case == 5)) test_case_5(); }

0 commit comments

Comments
 (0)