ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#207466 | #3738. 神奇公式 | wyz_ | 100 | 59ms | 1412kb | C++11 | 1.1kb | 2024-07-28 19:57:19 | 2024-07-28 20:40:23 |
answer
#include<bits/stdc++.h>
using namespace std;
int x,y,q,l,r;
map<int,int>a,b,mp;
vector<int>g,d;
void decompos_prime(int x,map<int,int>& mp){
while(!(x & 1))
x >>= 1, mp[2]++;
for(int i = 3; i * i <= x; i += 2){
while(x % i == 0)
x /= i, mp[i]++;
}
if(x != 1)
mp[x]++;
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> x >> y >> q;
decompos_prime(x,a);
decompos_prime(y,b);
for(auto& p : a){
if(b.count(p.first))
mp[p.first] = min(p.second,b[p.first]);
}
for(auto& p : mp){
for(int i = 1; i <= p.second; i++)
g.push_back(p.first);
}
int m = 1 << int(g.size());
for(int i = 1; i <= m; i++){
int ans = 1;
for(int j = 0; j < int(g.size()); j++){
if(i >> j & 1)
ans *= g[j];
}
d.push_back(ans);
}
sort(d.begin(),d.end());
while(q--){
cin >> l >> r;
auto it = lower_bound(d.begin(),d.end(),l);
if(it == d.end() || *it > r)
cout << "-1\n";
else{
int n = it - d.begin();
while(d[n] <= r && n < int(d.size()))
n++;
cout << d[n-1] << '\n';
}
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 11ms
memory: 1412kb
input:
348416640 134006400 9203 381 904 396 976 54 147 360 788 62 154 500 1000 33 703 223 851 267 972 294 7...
output:
891 960 144 752 144 990 660 846 960 752 220 891 891 891 594 396 891 960 752 540 752 960 640 594 810 ...
result:
ok 9203 numbers
Test #2:
score: 10
Accepted
time: 2ms
memory: 1292kb
input:
368398800 319278960 9318 259 853 150 428 426 984 65 257 293 967 304 859 99 928 189 730 493 990 278 7...
output:
840 420 924 252 924 840 924 720 990 720 495 924 924 990 560 924 792 660 770 630 886 924 660 924 630 ...
result:
ok 9318 numbers
Test #3:
score: 10
Accepted
time: 10ms
memory: 1320kb
input:
107575776 7683984 9970 318 927 405 988 132 834 6 445 268 611 252 863 467 979 443 997 330 948 187 650...
output:
924 968 792 441 594 847 968 968 924 648 924 882 297 792 924 539 924 792 891 336 252 792 968 891 924 ...
result:
ok 9970 numbers
Test #4:
score: 10
Accepted
time: 9ms
memory: 1316kb
input:
166418304 332836608 9808 33946 87926 10296 23243 29403 72901 38518 97074 27616 93987 24917 54546 281...
output:
86496 23088 70278 94128 93704 50986 98124 57664 84864 47064 66674 88192 76479 88192 35139 66674 9812...
result:
ok 9808 numbers
Test #5:
score: 10
Accepted
time: 4ms
memory: 1284kb
input:
63478620 437297160 9550 26045 62893 43092 86784 17496 52973 14241 51283 4367 14773 42292 88805 39658...
output:
61870 76665 51110 51110 13110 76665 76665 61870 74244 76665 24748 37122 76665 74244 76665 92805 9280...
result:
ok 9550 numbers
Test #6:
score: 10
Accepted
time: 2ms
memory: 1280kb
input:
19886000 333090500 9300 45696 93745 38251 94457 21687 95638 20536 71982 13115 26446 48043 96136 3986...
output:
81500 81500 81500 49715 20375 81500 81500 20375 40750 49715 81500 49715 49715 81500 40750 49715 3050...
result:
ok 9300 numbers
Test #7:
score: 10
Accepted
time: 3ms
memory: 1284kb
input:
202943400 304415100 9494 9035 45696 15576 69414 2237 47826 23377 88110 22630 49691 16652 65392 45948...
output:
41844 64020 47550 87175 47550 64020 92247 64020 53350 64020 52305 87175 87175 80025 95100 87175 8002...
result:
ok 9494 numbers
Test #8:
score: 10
Accepted
time: 4ms
memory: 1288kb
input:
409519616 255949760 9654 3529364 116950129 9643 832086 4776204 500233623 74 231 3881982 598796620 21...
output:
51189952 799843 51189952 209 51189952 51189952 25594976 64 51189952 168388 51189952 51189952 5118995...
result:
ok 9654 numbers
Test #9:
score: 10
Accepted
time: 6ms
memory: 1280kb
input:
203359194 67786398 9171 3979446 976089629 5599 201623 173333 837815033 57223 98444567 9 20 80 236 56...
output:
67786398 191487 67786398 67786398 18 213 67786398 67786398 2059 318246 389577 213 10974 11297733 677...
result:
ok 9171 numbers
Test #10:
score: 10
Accepted
time: 8ms
memory: 1296kb
input:
265920480 151954560 9127 413 34155 2906 181514 9946 640894 60 174 70 340 1091724 556442868 5670 3205...
output:
34040 171120 633144 160 333 37988640 316572 37988640 37988640 37988640 372 633144 37988640 245088 37...
result:
ok 9127 numbers