結果
| 問題 | 
                            No.1532 Different Products
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-06-04 22:51:33 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 493 ms / 4,000 ms | 
| コード長 | 1,235 bytes | 
| コンパイル時間 | 2,274 ms | 
| コンパイル使用メモリ | 189,656 KB | 
| 実行使用メモリ | 22,728 KB | 
| 最終ジャッジ日時 | 2024-11-20 05:28:53 | 
| 合計ジャッジ時間 | 19,832 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 62 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main(){
	int n;
	ll k;
	cin>>n>>k;
	unordered_map<ll, ll> ma, da;
	const int mid=30;
	ll ans;
	if(n<=mid){
		ma[1]=1;
		for(int i=1; i<=n; i++){
			vector<P> al;
			for(auto p : ma){
				if((ll)i*p.first<=k) al.push_back(P((ll)i*p.first, p.second));
			}
			for(P p : al) ma[p.first]+=p.second;
		}
		ll tot=0;
		for(auto p : ma) tot+=p.second;
		ans=tot-1;
	}
	else{
		ma[1]=1;
		for(int i=1; i<=mid; i++){
			vector<P> al;
			for(auto p : ma){
				if((ll)i*p.first<=k) al.push_back(P((ll)i*p.first, p.second));
			}
			for(P p : al) ma[p.first]+=p.second;
		}
		da[k]=1;
		for(int i=mid+1; i<=n; i++){
			vector<P> al;
			for(auto p : da){
				if(p.first/i>0) al.push_back(P(p.first/i, p.second));
			}
			for(P p : al) da[p.first]+=p.second;
		}
		unordered_set<ll> kse;
		for(auto p : ma) kse.insert(p.first);
		for(auto p : da) kse.insert(p.first);
		vector<ll> kl;
		for(ll e : kse) kl.push_back(e);
		sort(kl.begin(), kl.end());
		ll c=0, tot=0;
		for(ll e : kl){
			if(ma.count(e)) c+=ma[e];
			if(da.count(e)) tot+=c*da[e];
		}
		ans=tot-1;
	}
	cout<<ans<<endl;
	return 0;
}