結果

問題 No.1276 3枚のカード
ユーザー kmjpkmjp
提出日時 2020-10-30 23:12:50
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 313 ms / 2,000 ms
コード長 1,841 bytes
コンパイル時間 1,934 ms
使用メモリ 7,656 KB
最終ジャッジ日時 2023-02-21 15:59:45
合計ジャッジ時間 13,491 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
6,272 KB
testcase_01 AC 2 ms
6,268 KB
testcase_02 AC 2 ms
6,268 KB
testcase_03 AC 2 ms
6,256 KB
testcase_04 AC 2 ms
6,196 KB
testcase_05 AC 1 ms
6,204 KB
testcase_06 AC 2 ms
6,204 KB
testcase_07 AC 2 ms
6,252 KB
testcase_08 AC 2 ms
6,172 KB
testcase_09 AC 2 ms
6,248 KB
testcase_10 AC 269 ms
7,312 KB
testcase_11 AC 141 ms
6,196 KB
testcase_12 AC 173 ms
6,212 KB
testcase_13 AC 179 ms
6,304 KB
testcase_14 AC 31 ms
6,324 KB
testcase_15 AC 149 ms
6,204 KB
testcase_16 AC 290 ms
7,496 KB
testcase_17 AC 169 ms
6,188 KB
testcase_18 AC 134 ms
6,264 KB
testcase_19 AC 203 ms
6,488 KB
testcase_20 AC 129 ms
6,260 KB
testcase_21 AC 132 ms
6,176 KB
testcase_22 AC 296 ms
7,472 KB
testcase_23 AC 28 ms
6,272 KB
testcase_24 AC 192 ms
6,292 KB
testcase_25 AC 80 ms
6,176 KB
testcase_26 AC 232 ms
6,740 KB
testcase_27 AC 262 ms
7,196 KB
testcase_28 AC 254 ms
7,076 KB
testcase_29 AC 156 ms
6,252 KB
testcase_30 AC 44 ms
6,192 KB
testcase_31 AC 28 ms
6,324 KB
testcase_32 AC 84 ms
6,284 KB
testcase_33 AC 13 ms
6,204 KB
testcase_34 AC 61 ms
6,212 KB
testcase_35 AC 60 ms
6,196 KB
testcase_36 AC 11 ms
6,208 KB
testcase_37 AC 56 ms
6,176 KB
testcase_38 AC 42 ms
6,208 KB
testcase_39 AC 87 ms
6,272 KB
testcase_40 AC 284 ms
7,460 KB
testcase_41 AC 238 ms
6,808 KB
testcase_42 AC 256 ms
7,008 KB
testcase_43 AC 226 ms
6,780 KB
testcase_44 AC 311 ms
7,568 KB
testcase_45 AC 284 ms
7,420 KB
testcase_46 AC 284 ms
7,412 KB
testcase_47 AC 239 ms
6,812 KB
testcase_48 AC 230 ms
6,724 KB
testcase_49 AC 258 ms
7,148 KB
testcase_50 AC 282 ms
7,364 KB
testcase_51 AC 246 ms
6,984 KB
testcase_52 AC 214 ms
6,548 KB
testcase_53 AC 247 ms
7,048 KB
testcase_54 AC 281 ms
7,360 KB
testcase_55 AC 223 ms
6,724 KB
testcase_56 AC 217 ms
6,624 KB
testcase_57 AC 270 ms
7,236 KB
testcase_58 AC 280 ms
7,312 KB
testcase_59 AC 248 ms
6,908 KB
testcase_60 AC 313 ms
7,656 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