結果
問題 | No.2785 四乗足す四の末尾の0 |
ユーザー |
|
提出日時 | 2024-06-14 22:53:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 118 ms / 2,000 ms |
コード長 | 1,296 bytes |
コンパイル時間 | 2,036 ms |
コンパイル使用メモリ | 196,936 KB |
最終ジャッジ日時 | 2025-02-21 22:18:57 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) template<typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template<typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } void solve(); int main() { cin.tie(nullptr)->sync_with_stdio(false); cout << fixed << setprecision(20); int t = 1; cin >> t; while (t--) { solve(); } } __int128_t modpow(__int128_t a, __int128_t n, __int128_t mod) { __int128_t ret = 1; a %= mod; while (n) { if (n & 1) { ret = ret * a % mod; } a = a * a % mod; n >>= 1; } return ret; } bool is_prime(__int128_t n){ if(n==2)return 1; if(n%2==0)return 0; vector<int>A={2,3,5,7,11,13,17,19,23,29,31,37}; if(n<=A.back()){ for(int a:A)if(n==a)return 1; return 0; } for(int a:A){ if(modpow(a,n-1,n)!=1)return 0; __int128_t d=(n-1)/2; while(d%2==0&&modpow(a,d,n)==1)d/=2; __int128_t r=modpow(a,d,n); if(r!=1&&r!=n-1)return 0; } return 1; } int N; void solve() { cin>>N; __int128_t x(N),A=x*x*x*x+4; cout<<(is_prime(A)?"Yes":"No")<<'\n'; int ans=0; while(A%10==0){ ++ans; A/=10; } cout<<ans<<'\n'; }