国外 家具 网站模板下载,公司电商网站开发合同,百度大数据,软件下载网站开发盲盒problemsolutioncodeproblem
有 2n2n2n 个盲盒#xff0c;每个盲盒有一个惊喜值 aia_iai。
打开恰好 nnn 个盲盒#xff0c;获得的惊喜值为这些盲盒惊喜值的最大公约数。
求能获得的最大惊喜值。 n≤1e5,ai≤1e12n\le 1e5,a_i\le 1e12n≤1e5,ai≤1e12。
solution…
盲盒problemsolutioncodeproblem
有 2n2n2n 个盲盒每个盲盒有一个惊喜值 aia_iai。
打开恰好 nnn 个盲盒获得的惊喜值为这些盲盒惊喜值的最大公约数。
求能获得的最大惊喜值。
n≤1e5,ai≤1e12n\le 1e5,a_i\le 1e12n≤1e5,ai≤1e12。
solution
我是真的讨厌这种随机的正解没什么就是想cao
有一个性质如果随机一个盲盒那么它被打开的概率为 12\frac{1}{2}21。
即这个盲盒的某个因子是最后答案的概率为 12\frac{1}{2}21。
还有一个性质通过打表发现在 1e121e121e12 内因子个数最多只有 672067206720 个。
所以只需要随机盲盒然后暴力判断其每个因子是否有被 ≥n\ge n≥n 个盲盒含有。
最后为了正确性就多随机几个数。
显然正确性是跟随机次数挂钩的随机 xxx 次那么出错的概率就是这 xxx 次的数都不是被选择盲盒概率为 (12)x(\frac{1}{2})^x(21)x。
code
#include ctime
#include cstdio
#include random
#include algorithm
using namespace std;
#define maxn 200005
#define int long long
int n, ans;
int a[maxn], f[maxn];void check( int x ) {int cnt 0;for( int i 1;i * i x;i )if( x % i 0 ) {if( i ans ) f[ cnt] i;if( x / i ans ) f[ cnt] x / i;}for( int i 1;i cnt;i )if( f[i] ans ) {for( int j 1, tot 0;j n;j )if( a[j] % f[i] 0 ) {tot ;if( tot ( n 1 ) ) {ans f[i];break;}}}
}signed main() {scanf( %lld, n ); n 1;for( int i 1;i n;i ) scanf( %lld, a[i] );mt19937 wwl( time( 0 ) );uniform_int_distribution int range( 1, n );for( int i 1;i 20;i ) {int x range( wwl );check( a[x] );}printf( %lld\n, ans );return 0;
}