题解:B4394 [常州市赛 2025] 公约数与公倍数
这题可以先从简单的情况开始考虑
\
\
注意到有一种特殊性质为a为奇数,我们设
int s[30][4] = {{499999999,300000002,300000000,800000000},
{249999999,300000003,300000000,800000000},
{124999999,300000005,300000000,800000000},
{62499999,300000009,300000000,800000000},
{31249999,300000017,300000000,800000000},
{15624999,300000033,300000000,800000000},
{7812499,300000065,300000000,800000000},
{3906249,300000129,300000000,800000000},
{1953124,300000257,300000000,800000000},
{976562,300000001,300000000,800000000},
{488280,300001537,300000000,800000000},
{244140,300000513,300000000,800000000},
{122069,300006657,300000000,800000000},
{61034,300010753,300000000,800000000},
{30517,300002561,300000000,800000000},
{15258,300018945,300000000,800000000},
{7628,300117249,300000000,800000000},
{3814,300051713,300000000,800000000},
{1906,300444929,300000000,800000000},
{953,300182785,300000000,800000000},
{476,300707073,300000000,800000000},
{237,303852801,300000000,800000000},
{118,305949953,300000000,800000000},
{59,301755649,300000000,800000000},
{29,310144257,300000000,800000000},
{14,326921473,300000000,800000000},
{6,427584769,300000000,800000000},
{3,360475905,300000000,800000000},
{1,494693633,300000000,800000000},
{0,763129089,300000000,800000000}
};
其中,
#include<bits/stdc++.h>
using namespace std;
int T,a,n,k;
int power[30];
int s[30][4] = {{499999999,300000002,300000000,800000000},
{249999999,300000003,300000000,800000000},
{124999999,300000005,300000000,800000000},
{62499999,300000009,300000000,800000000},
{31249999,300000017,300000000,800000000},
{15624999,300000033,300000000,800000000},
{7812499,300000065,300000000,800000000},
{3906249,300000129,300000000,800000000},
{1953124,300000257,300000000,800000000},
{976562,300000001,300000000,800000000},
{488280,300001537,300000000,800000000},
{244140,300000513,300000000,800000000},
{122069,300006657,300000000,800000000},
{61034,300010753,300000000,800000000},
{30517,300002561,300000000,800000000},
{15258,300018945,300000000,800000000},
{7628,300117249,300000000,800000000},
{3814,300051713,300000000,800000000},
{1906,300444929,300000000,800000000},
{953,300182785,300000000,800000000},
{476,300707073,300000000,800000000},
{237,303852801,300000000,800000000},
{118,305949953,300000000,800000000},
{59,301755649,300000000,800000000},
{29,310144257,300000000,800000000},
{14,326921473,300000000,800000000},
{6,427584769,300000000,800000000},
{3,360475905,300000000,800000000},
{1,494693633,300000000,800000000},
{0,763129089,300000000,800000000}
};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>T;
power[0] = 1;
for(int i = 1;i <= 29;i++) power[i] = power[i - 1] * 2;
while(T--)
{
cin>>a;
n = 0;
if(a % 65536 == 0)
{
a /= 65536;
n += 16;
}
if(a % 256 == 0)
{
a /= 256;
n += 8;
}
if(a % 16 == 0)
{
a /= 16;
n += 4;
}
if(a % 4 == 0)
{
a /= 4;
n += 2;
}
if(a % 2 == 0)
{
a /= 2;
n += 1;
}
k = (a - 1) / 2;
if(k == s[n][0]) cout<<s[n][1]<<' '<<s[n][2]<<' '<<s[n][3]<<'\n';
else cout<<power[n]<<' '<<power[n] * 2<<' '<<power[n] * (2 * k + 3)<<'\n';
}
return 0;
}