QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84157#5503. Euclidean AlgorithmTheOneYouWantAC ✓26467ms3464kbC++202.5kb2023-03-05 20:22:132023-03-05 20:22:15

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-05 20:22:15]
  • 评测
  • 测评结果:AC
  • 用时:26467ms
  • 内存:3464kb
  • [2023-03-05 20:22:13]
  • 提交

answer

//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


void solve() {
	ll n;
	cin >> n;
	ll ans = 0;
	//count small b
	ll b = 1;

	ll mxb = 1;
	for(;mxb*mxb <= n; mxb++);

	for(;b*b <= n; b++) {
		ll a = 1;
		for(;a*a <= n/b; a++) {
			ans += n/(a*b+1);
		}

		for(ll k = 1; k <= n/(a*b+1); k++) {
			ll maxval = (n-k)/(b*k);
			ll minval = (n-k-1)/(b*(k+1)) + 1;
			if(k == n/(a*b+1))
				minval = max(minval, a);
			if(maxval >= minval)
				ans += k*(maxval - minval + 1);
			ll cut = max(mxb, minval);
			if(maxval >= cut)
				ans += k*(maxval - cut+1);
		}
	}
	cout << ans << ln;

}

int main(){
	fastio;
	int t;
	cin >> t;
	while(t--)
		solve();
	

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3284kb

input:

3
2
5
14

output:

1
9
62

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 14432ms
memory: 3368kb

input:

3
29107867360
65171672278
41641960535

output:

8921593237533
21300450379732
13136180138425

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 25803ms
memory: 3460kb

input:

3
90076809172
100000000000
99913139559

output:

30192292781431
33790187414013
33758574429172

result:

ok 3 lines

Test #4:

score: 0
Accepted
time: 26467ms
memory: 3376kb

input:

3
99997992652
99832769119
99997176887

output:

33789456663124
33729325483151
33789159765448

result:

ok 3 lines

Test #5:

score: 0
Accepted
time: 6669ms
memory: 3352kb

input:

30
500000004
991026973
875910473
804967563
817240034
859023503
871905363
994897763
533952899
999999996
500000003
851714124
618161807
500000002
500000000
642565501
703104463
520948789
513785485
999999997
1000000000
579195816
999999998
965942980
870891922
571793533
723494232
999999999
590539561
500000...

output:

106931694901
226252654431
197658605222
180202748830
183212809398
193491469207
196669619643
227219558906
114922441260
228494567273
106931693908
191690034392
134938724588
106931693896
106931693226
140788123843
155385451308
111856217326
110170204124
228494567397
228494568703
125643111389
228494567464
2...

result:

ok 30 lines

Test #6:

score: 0
Accepted
time: 2587ms
memory: 3464kb

input:

3000
684920
881740
317776
310160
23336
999832
819596
973868
166
449876
290325
912538
999939
282224
600310
448121
816943
972518
895590
612220
349205
52931
999880
267637
549817
513310
182
852220
314635
377356
96591
628319
999757
597508
896048
116
71393
735158
203
282
68
33305
762621
745035
922434
5853...

output:

67611341
90223986
28005207
27233331
1319648
104127915
83003612
101051578
2569
41769873
25235715
93827427
104140754
24424464
58142642
41582414
82697155
100892535
91843138
59465231
31217321
3478468
104133259
22974376
52576328
48594603
2923
86785163
27686009
34130245
7039269
61257408
104119319
57832117...

result:

ok 3000 lines