結果
| 問題 | 
                            No.2751 429-like Number
                             | 
                    
| コンテスト | |
| ユーザー | 
                             naut3
                         | 
                    
| 提出日時 | 2024-05-10 22:58:04 | 
| 言語 | Rust  (1.83.0 + proconio)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,164 bytes | 
| コンパイル時間 | 14,205 ms | 
| コンパイル使用メモリ | 401,656 KB | 
| 実行使用メモリ | 13,640 KB | 
| 最終ジャッジ日時 | 2024-12-20 07:07:19 | 
| 合計ジャッジ時間 | 29,796 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 6 | 
| other | AC * 7 WA * 14 TLE * 1 | 
ソースコード
#![allow(non_snake_case, unused_imports)]
use proconio::{fastout, input, marker::*};
#[fastout]
fn main() {
    input! {
        Q: usize,
        A: [usize; Q],
    }
    for mut a in A {
        let mut cnt = 0;
        for i in 2.. {
            if i * i * i > a {
                break;
            }
            if a % i == 0 {
                while a % i == 0 {
                    cnt += 1;
                    a /= i;
                }
                break;
            }
        }
        for i in 2.. {
            if i * i > a {
                break;
            }
            if a % i == 0 {
                while a % i == 0 {
                    cnt += 1;
                    a /= i;
                }
                break;
            }
        }
        if (cnt == 2 && miller_rabin_primality_test(a)) || cnt == 3 {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}
pub fn miller_rabin_primality_test(n: usize) -> bool {
    fn pow(a: usize, b: usize, m: usize) -> usize {
        let (mut a, mut b, m) = (a as u128, b as u128, m as u128);
        let mut ret = 1;
        a %= m;
        while b > 0 {
            if b & 1 == 1 {
                ret = (ret * a) % m;
            }
            a = (a * a) % m;
            b >>= 1;
        }
        ret as usize
    }
    if n == 0 || n == 1 {
        false
    } else if n == 2 {
        true
    } else if n % 2 == 0 {
        false
    } else {
        const A: [usize; 7] = [2, 325, 9375, 28178, 450775, 9780504, 1795265022];
        let mut s = 0;
        let mut d = n - 1;
        while d % 2 == 0 {
            s += 1;
            d >>= 1;
        }
        for a in A {
            if a % n == 0 {
                return true;
            }
            let mut x = pow(a, d, n);
            if x != 1 {
                for t in 0..s {
                    if x == n - 1 {
                        break;
                    }
                    x = pow(x, 2, n);
                    if t == s - 1 {
                        return false;
                    }
                }
            }
        }
        true
    }
}
            
            
            
        
            
naut3