結果

問題 No.3824 GCD of All
コンテスト
ユーザー okkuu
提出日時 2026-11-20 18:46:39
言語 C++23(gnu拡張gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=gnu++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 47 ms / 2,000 ms
+ 163µs
コード長 1,393 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,496 ms
コンパイル使用メモリ 403,816 KB
実行使用メモリ 21,368 KB
最終ジャッジ日時 2026-11-22 12:44:51
合計ジャッジ時間 7,047 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//*/
#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_cxx;
//using namespace __gnu_pbds;
/*
#include<atcoder/all>
using namespace atcoder;
using mint=modint998244353;
using Mint=modint1000000007;
//*/
using uint=unsigned int;
using ll=long long;
using ull=unsigned long long;
using P=pair<int,int>;
using Pl=pair<ll,ll>;
constexpr int mod=998244353;
constexpr int Mod=1e9+7;
constexpr int inf=Mod;
constexpr ll linf=(ll)inf*inf;
constexpr int dx[]={1,0,0,-1},dy[]={0,1,-1,0};
constexpr int Dx[]={1,1,1,0,0,-1,-1,-1},Dy[]={1,0,-1,1,-1,1,0,-1};
struct initio{
	initio(){
		cin.tie(0)->sync_with_stdio(0);
		cout<<fixed<<setprecision(20);
	};
}iio;
template<class T>
bool chmax(T&a,const T&b){
	if(a<b){
		a=b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a,const T&b){
	if(a>b){
		a=b;
		return 1;
	}
	return 0;
}
int fl2(ll n){
	return 63-__builtin_clzll(n);
}
int main(){
	ll m;
	cin>>m;
	vector<ll>d,q;
	for(ll i=1;i*i<=m;i++){
		if(m%i==0){
			d.push_back(i);
			if(m/i!=i)
				d.push_back(m/i);
		}
	}
	sort(d.begin(),d.end());
	ll l=1;
	while(l<=m){
		q.push_back(l);
		l=m/(m/l)+1;
	}
	q.push_back(m+1);
	ll ans=0;
	for(int i=0;i+1<q.size();i++){
		int idx=upper_bound(d.begin(),d.end(),m/q[i])-d.begin();
		ans+=d[idx-1]*(q[i+1]-q[i]);
	}
	cout<<ans<<endl;
}
0