結果

問題 No.1276 3枚のカード
ユーザー 👑 kmjpkmjp
提出日時 2020-10-30 23:12:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 1,841 bytes
コンパイル時間 2,286 ms
コンパイル使用メモリ 209,340 KB
実行使用メモリ 7,576 KB
最終ジャッジ日時 2023-09-29 08:18:30
合計ジャッジ時間 15,202 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 275 ms
7,100 KB
testcase_11 AC 141 ms
5,632 KB
testcase_12 AC 174 ms
6,116 KB
testcase_13 AC 181 ms
6,084 KB
testcase_14 AC 30 ms
4,376 KB
testcase_15 AC 150 ms
5,876 KB
testcase_16 AC 299 ms
7,312 KB
testcase_17 AC 170 ms
6,056 KB
testcase_18 AC 134 ms
5,544 KB
testcase_19 AC 204 ms
6,416 KB
testcase_20 AC 128 ms
5,488 KB
testcase_21 AC 134 ms
5,588 KB
testcase_22 AC 304 ms
7,480 KB
testcase_23 AC 28 ms
4,380 KB
testcase_24 AC 195 ms
6,236 KB
testcase_25 AC 79 ms
4,836 KB
testcase_26 AC 238 ms
6,704 KB
testcase_27 AC 269 ms
7,136 KB
testcase_28 AC 258 ms
7,024 KB
testcase_29 AC 157 ms
5,884 KB
testcase_30 AC 43 ms
4,380 KB
testcase_31 AC 28 ms
4,376 KB
testcase_32 AC 83 ms
4,784 KB
testcase_33 AC 12 ms
4,376 KB
testcase_34 AC 61 ms
4,692 KB
testcase_35 AC 59 ms
4,480 KB
testcase_36 AC 10 ms
4,376 KB
testcase_37 AC 55 ms
4,392 KB
testcase_38 AC 42 ms
4,376 KB
testcase_39 AC 91 ms
4,848 KB
testcase_40 AC 291 ms
7,264 KB
testcase_41 AC 243 ms
6,764 KB
testcase_42 AC 263 ms
6,952 KB
testcase_43 AC 232 ms
6,656 KB
testcase_44 AC 318 ms
7,516 KB
testcase_45 AC 291 ms
7,320 KB
testcase_46 AC 290 ms
7,284 KB
testcase_47 AC 248 ms
6,796 KB
testcase_48 AC 273 ms
6,752 KB
testcase_49 AC 262 ms
7,084 KB
testcase_50 AC 289 ms
7,216 KB
testcase_51 AC 251 ms
7,020 KB
testcase_52 AC 218 ms
6,504 KB
testcase_53 AC 255 ms
7,040 KB
testcase_54 AC 287 ms
7,284 KB
testcase_55 AC 226 ms
6,612 KB
testcase_56 AC 220 ms
6,512 KB
testcase_57 AC 277 ms
7,168 KB
testcase_58 AC 286 ms
7,504 KB
testcase_59 AC 252 ms
6,928 KB
testcase_60 AC 320 ms
7,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
const ll mo=1000000007;

ll slow(int v) {
	ll ret=0;
	int i;
	for(i=2;i<=v;i++) {
		ll p=v/i;
		if(p<1) break;
		ret+=p-1;
	}
	return ret%mo;
}

ll hoge(int v) {
	if(v<=100) return slow(v);
	ll ret=0;
	int sq=sqrt(v)+2;
	map<int,int> M; // M[x]= |N/i|がxになる数
	int i;
	for(i=2;i<=sq;i++) ret+=v/i-1;
	ret%=mo;
	for(i=1;i<=sq;i++) {
		int L=v/i;
		int R=max(sq+1,v/(i+1)+1);
		if(L>=R) (ret+=1LL*(i-1)*(L-R+1))%=mo;
		else break;
	}
	return ret%mo;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	//for(i=1;i<=20;i++) cout<<hoge(i)<<endl;
	
	cin>>N;
	ll ret=0;
	map<int,int> M; // M[x]= |N/i|がxになる数
	for(i=1;i<=min(200000,N);i++) M[N/i]++;
	for(i=1;i<=20000;i++) {
		int L=N/i;
		int R=max(200001,N/(i+1)+1);
		if(L>=R) M[i]+=L-R+1;
	}
	
	
	// ? x aX
	FORR(m,M) {
		//cout<<m.first<<" "<<m.second<<endl;
		ll b=m.first-1;
		// ? x bx (b>1)
		(ret+=(N-2)*b%mo*m.second)%=mo;
		// ax x bx (a>=1, b>1, a!=b)を引く
		ll a=(m.first-2);
		(ret-=a*b%mo*m.second)%=mo;
	}
	// X aX abX (1<a<b)
	FORR(m,M) {
		ll pat=hoge(m.first);
		(ret-=pat*m.second)%=mo;
	}
	ret=(ret%mo+mo)%mo;
	
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0