QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#137178#5503. Euclidean AlgorithmfryanML 0ms3468kbC++142.6kb2023-08-10 01:39:102023-08-10 01:39:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 01:39:13]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:3468kb
  • [2023-08-10 01:39:10]
  • 提交

answer

// Problem: M - W3P3: Euclidean Algorithm
// Contest: Virtual Judge - 602 - Season 2023 - HW Series 1
// URL: https://vjudge.net/contest/570461#problem/M
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;

//numbers
using ll=long long;
#define int ll
using ld=long double;
//pairs
#define P pair
#define pi P<int,int>
#define ff first
#define ss second
#define mp make_pair
//std data structure
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
//vectors
#define V vector
#define vi V<int>
#define v2i V<vi>
#define vpi V<pi>
#define vsi V<si>
#define pb push_back
//sets
#define S set
#define MS multiset
#define US unordered_set
#define si S<int>
#define msi MS<int>
#define usi US<int>
#define ins insert
#define era erase
//maps
#define M map
#define UM unordered_map
#define mii M<int,int>
#define mivi UM<int,vi>
#define misi UM<int,si>
#define umii UM<int,int>
#define umivi UM<int,vi>
#define umisi UM<int,si>
//queues
#define Q queue
#define PQ priority_queue
#define qi Q<int>
#define qpi Q<pi>
#define pqi PQ<int>
#define rpqi PQ<int,greater<int>>
#define pqpi PQ<pi>
#define rpqpi PQ<pi,greater<pi>>
//constants
const int MOD=998244353;
const int INF=922337203685477580;
//nt functions
int binpow(int a, int b, int m=MOD) {
    a%=m; int res=1;
    while (b>0) {
        if (b&1) res=res*a%m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}
int gcd (int a, int b) {
    return b?gcd (b,a%b):a;
}
int lcm (int a, int b) {
    return a/gcd(a,b)*b;
}
int inv(int i, int m=MOD) {
	return binpow(i, m-2, m);
}
//new header wip

void solve() {
	int n; cin>>n; si rev; int ans=0;
	for (int i=1; i<=sqrt(n); i++) {
		rev.ins(i); rev.ins(n/i);
	}
	
	for (auto i:rev) {
		if (i==1) {continue;}
		int nr=i-1;
		int cv=0;
		for (int p=1; p<=sqrt(nr); p++) {
			cv+=nr/p-p+1;
		}
		cv*=2;
		for (int sq=1; sq<=sqrt(nr); sq++) {
			cv--;
		}
		int nocc=((int)(n/i))-((int)(n/(i+1)));
		ans+=cv*nocc;
	}
	
	cout<<ans<<"\n";
}

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
		
	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: 0ms
memory: 3468kb

input:

3
2
5
14

output:

1
9
62

result:

ok 3 lines

Test #2:

score: -100
Memory Limit Exceeded

input:

3
29107867360
65171672278
41641960535

output:


result: