題解/算法 {198. 反素数}

@Link

Solution

Suppose a = p 1 a 1 ∗ p 2 a 2 ∗ . . . a = p_1^{a_1} * p_2^{a_2} * ... a=p1a1p2a2... where p 1 ≤ p 2 ≤ . . . p_1 \leq p_2 \leq ... p1p2... is an Anti-Prime, it would has some properties:
. a 1 ≥ a 2 ≥ . . . a_1 \geq a_2 \geq ... a1a2...; (if not, e.g., a = 2 1 ∗ 3 2 a=2^1 * 3^2 a=2132, another number b = 2 2 ∗ 3 1 b = 2^2 * 3^1 b=2231 which own the same Divisor-Count with a a a, while b < a b < a b<a implies a a a is not Anti-Prime)
. p 1 = 2 , p 2 = 3 , p 3 = 5 , . . . p_1 = 2, p_2 = 3, p_3 = 5, ... p1=2,p2=3,p3=5,...; (the analysis is similar to the above)

Due to these two properties, actually we can use DFS-Brute to finding all such numbers a a a (notice, a a a may not be a Anti-Prime; e.g., in the range of int, the number of such a a a is greater than the number of Anti-Prime), the number of such a a a would not too much even in the whole range of int, cuz 2 ∗ 3 ∗ 5 ∗ 7 ∗ . . . 2*3*5*7*... 2357... at most 9 9 9 Primes-Factor would attain the maximum of int;

Code

int P[] = {2, 3, 5, 7, 11, 13, 17, 19, 23};
long long N;
long long Cont, Ans;
void Dfs( int _ind, int _power, int _cont, long long _n){
    if( _ind >= 9){ return;}
    long long cur = 1;
    for( int p = 1; p <= _power; ++p){
        cur *= P[ _ind];
        if( _n * cur > N){ break;}
        if( (_cont * (p + 1) > Cont) || ((_cont * (p + 1) == Cont) && (_n * cur < Ans))){
            Cont = _cont * (p + 1);
            Ans = _n * cur;
        }
        Dfs( _ind + 1, p, _cont * (p + 1), _n * cur);
    }
}

scanf("%lld", &N);
Cont = 1, Ans = 1;
Dfs( 0, 100, 1, 1);
cout<< Ans;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值