結果
問題 | No.1022 Power Equation |
ユーザー |
![]() |
提出日時 | 2020-04-10 22:05:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 1,329 bytes |
コンパイル時間 | 1,679 ms |
コンパイル使用メモリ | 169,036 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 20:25:58 |
合計ジャッジ時間 | 2,168 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
#include <bits/stdc++.h>#include <iomanip>using namespace std;#define reps(i,s,n) for(int i = s; i < n; i++)#define rep(i,n) reps(i,0,n)#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)#define Rrep(i,n) Rreps(i,n,0)#define ALL(a) a.begin(), a.end()#define fi first#define se secondtypedef long long ll;typedef vector<ll> vec;typedef vector<vec> mat;ll N,M,H,W,K,Q,A,B;string S;const ll MOD = 998244353;//const ll MOD = (1e+9) + 7;const ll INF = 1LL<<60;typedef pair<ll, ll> P;ll extgcd(ll a, ll b, ll &x, ll &y){ll d = a;if(b != 0){d = extgcd(b, a%b, y, x);y -= (a/b) * x;}else{x=1;y=0;}return d;}ll fastpow(ll a, ll pw) {ll res = 1;while (pw) {if(a > 1e+9) return 2e+9;if (pw & 1) res = res * a;a = a * a;pw >>= 1;}return res;}ll solve(ll n){ll res = n * n + (n - 1) * n;reps(b, 2, min(31LL, n + 1)){reps(d, 1, b){ll x, y;if(extgcd(b, d, x, y) == 1) {reps(tn, 2, 32000) {ll c = fastpow(tn, b);if(c > n) break;res += 2 * (n / b);}}}}return res;}int main() {cin>>Q;rep(i,Q){cin>>N;cout<<solve(N)<<endl;}}