結果

問題 No.1022 Power Equation
ユーザー hanbei_dayohanbei_dayo
提出日時 2020-08-31 21:25:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 967 ms / 2,000 ms
コード長 1,370 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 105,276 KB
実行使用メモリ 6,416 KB
最終ジャッジ日時 2023-08-10 17:47:07
合計ジャッジ時間 6,118 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 629 ms
6,324 KB
testcase_05 AC 967 ms
6,416 KB
testcase_06 AC 914 ms
6,356 KB
testcase_07 AC 934 ms
6,336 KB
testcase_08 AC 465 ms
6,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
#include <deque>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
 
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}



int main(void){
    int T;
    cin>>T;
    for(int i=0;i<T;i++){
        ll n;
        cin>>n;
        ll ans = n*(n-1)+n*n;
        set<int>s;
        for(ll i=2;i*i<=n;i++){
            if(s.count(i)==1)continue;
            vector<ll>p;
            ll index = 1;
            for(ll j=i;j<=n;j*=i){
                s.insert(j);
                p.push_back(index);
                index++;
            }
            for(ll j=0;j<p.size();j++){
                for(ll k=0;k<p.size();k++){
                    if(j==k)continue;
                    ll g = gcd(p[j],p[k]);
                    ll p1 = p[j]/g;
                    ll p2 = p[k]/g;
                    ll n1 = n/max(p1,p2);
                    ans+=n1;
                }
            }
        }
        cout<<ans<<endl;
    }
	return 0;
}
0