結果
| 問題 | No.1022 Power Equation |
| コンテスト | |
| ユーザー |
catupper
|
| 提出日時 | 2020-04-10 22:42:38 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,301 bytes |
| コンパイル時間 | 575 ms |
| コンパイル使用メモリ | 72,180 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-15 21:32:00 |
| 合計ジャッジ時間 | 1,097 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 |
ソースコード
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
Int gcd(int x, int y){
if(x == 0)return y;
return gcd(y % x, x);
}
Int totient(int x){
Int ans = 0;
for(int i = 1;i <= x;i++){
ans += gcd(i, x) == 1;
}
return ans;
}
Int larger(Int a, Int b,Int x){
Int tmp = 1;
for(int i = 5;i >= 0;i--){
tmp *= tmp;
if(tmp > x)return true;
if((b & (1 << i)) == 0)continue;
tmp *= a;
if(tmp > x)return true;
}
return false;
}
void solve(){
Int n;
cin >> n;
Int ans = n*n * 2 - n;
for(Int q = 2;q < 40;q++){
Int bottom = 0, top = n;
while(top - bottom > 1){
Int mid = (top + bottom) / 2;
if(larger(mid, q, n))top = mid;
else bottom = mid;
}
if(bottom == 1)break;
ans += (n / q) * totient(q) * (bottom -1)* 2;
}
cout << ans << endl;
}
int main(){
int t;
cin >> t;
while(t--)solve();
return 0;
}
catupper