結果
| 問題 | No.3686 Coprime Sum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-04 04:55:34 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 302 ms / 2,000 ms |
| + 821µs | |
| コード長 | 3,292 bytes |
| 記録 | |
| コンパイル時間 | 2,023 ms |
| コンパイル使用メモリ | 347,304 KB |
| 実行使用メモリ | 211,140 KB |
| 最終ジャッジ日時 | 2026-10-04 04:55:40 |
| 合計ジャッジ時間 | 5,036 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
/*
#include<kyopro/master>
namespace my{entry
void main(){
LL(N,M);
auto mobius=LinearSieve<ll>(min(N,M)).mobius_enumerate();
use_ml998244353
ml ans=0;
fo(d,1,min(N,M)+1){
ans+=(ml)mobius[d]*triangular(N/d)*d*triangular(M/d)*d;
}
pp(ans);
}}*/
#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include<atcoder/modint>
#endif
using namespace std;
#define eb emplace_back
#define RD(T,...) T __VA_ARGS__;lin(__VA_ARGS__)
#define LL(...) RD(ll,__VA_ARGS__)
#define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
#define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);}
#define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{
#define use_ml998244353 using ml=atcoder::modint998244353;
namespace my{
auto&operator<<(ostream&o,const atcoder::modint998244353&x){return o<<(int)x.val();}
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
using i8=int8_t;
template<class T>constexpr auto for_range(T s,T a,T b,T c=1){return array{a-s,b,(1-s*2)*c};}
void lin(auto&...a){(cin>>...>>a);}
auto min(auto...a){return min(initializer_list<common_type_t<decltype(a)...>>{a...});}
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
}
namespace my{
template<class V>struct vec;
template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int D,class T>using hvec=hvec_helper<D,T>::type;
template<class V>struct vec:vector<V>{
using vector<V>::vector;
auto&emplace_back(auto&&...a){vector<V>::emplace_back(std::forward<decltype(a)>(a)...);return*this;}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
}
namespace my{
template<class T>T triangular(T n){return n*(n+1)/2;}
}
namespace my{
ll mobius_prime_pow(ll,i8 k,ll){return-(k==1);}
}
namespace my{
template<class T>class LinearSieve{
public:
T n;
vec<int>lpf;
vec<i8>lpf_ord;
vec<int>lpf_pow;
vec<int>lpf_pow_except;
vec<int>primes;
LinearSieve(T n):n(n),lpf(n+1,-1),lpf_ord(n+1),lpf_pow(n+1),lpf_pow_except(n+1){
lpf[1]=lpf_ord[1]=lpf_pow[1]=lpf_pow_except[1]=1;
fo(i,2,n+1){
if(lpf[i]==-1)primes.eb(lpf[i]=i);
fe(primes,p){
if(p*i>n||p>lpf[i])break;
lpf[p*i]=p;
}
int j=i/lpf[i];
lpf_ord[i]=lpf_ord[j]*(lpf[i]==lpf[j])+1;
lpf_pow[i]=((lpf_pow[j]-1)*(lpf[i]==lpf[j])+1)*lpf[i];
lpf_pow_except[i]=i/lpf_pow[i];
}
}
auto multiplicative_function_enumerate(const auto&f)const{
vec<T>r(n+1);
r[1]=1;
fo(i,2,n+1)r[i]=f(lpf[i],lpf_ord[i],lpf_pow[i])*r[lpf_pow_except[i]];
return r;
}
auto mobius_enumerate()const{return multiplicative_function_enumerate(mobius_prime_pow);}
};
}
namespace my{entry
void main(){
LL(N,M);
auto mobius=LinearSieve<ll>(min(N,M)).mobius_enumerate();
use_ml998244353
ml ans=0;
fo(d,1,min(N,M)+1){
ans+=(ml)mobius[d]*triangular(N/d)*d*triangular(M/d)*d;
}
pp(ans);
}}