結果

問題 No.3824 GCD of All
コンテスト
ユーザー Rho
提出日時 2026-11-08 05:19:10
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 4 ms / 2,000 ms
+ 139µs
コード長 1,809 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,594 ms
コンパイル使用メモリ 382,528 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2026-11-22 12:37:28
合計ジャッジ時間 4,881 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge6_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/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ull=unsigned long long;
typedef pair<ll,ll> P;
#define vec vector
#define pb emplace_back
#define fs first
#define sc second
#define pcnt __builtin_popcountll
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rng(i,s,t) for(ll i=s;i<t;i++)
#define len(a) int((a).size())
#define all(a) a.begin(),a.end()
#define compress(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
constexpr ll INF=4e18;
constexpr ld EPS=1e-11;
template<typename T> bool inline chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool inline chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename itr> void printvec(itr begin, itr end) {
	for (itr p = begin; p < end; p++){
		if(p!=begin)cout<<" "; cout << *p;
	}
	cout << endl;
}
template <class T> T makevec(T value) {return value;}
template <class T, class... Args,
		std::enable_if_t<(sizeof...(Args) > 0), int> = 0>
auto makevec(std::size_t n, Args... args) {
	auto inner = makevec<T>(args...);
	return std::vector<decltype(inner)>(n, inner);
}

#include "atcoder/modint.hpp"
using namespace atcoder;
typedef modint998244353 mint;
const ll mod=998244353;

vector<ll>divisor(ll n){
	vector<ll>res;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			res.push_back(i);
			if(i*i!=n)res.push_back(n/i);
		}
	}
	sort(all(res));
	return res;
}

int main(){
	ll m;
	cin>>m;
	auto d=divisor(m);
	ll ans=0;
	for(int i=0;i+1<d.size();i++){
		ans+=d[i]*(m/d[i]-m/d[i+1]);
	}
	ans+=d[d.size()-1];
	cout<<ans<<endl;
}

/*
f(N)=d ただしdはMの約数かつdN<=M
答えがdになる条件:N<=M/d
逆にdを列挙したとき、対応するNは[M/d,M/d')
*/
0