QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137180 | #5503. Euclidean Algorithm | fryan | AC ✓ | 4986ms | 3540kb | C++14 | 2.9kb | 2023-08-10 01:59:53 | 2023-08-10 01:59:55 |
Judging History
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
int t;
int n;
int s;
int v1,v2;
int cv1, cv2;
int noc1,noc2;
int ans;
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin>>t;
while (t--) {
cin>>n; ans=0;
s=sqrt(n);
for (int i=1; i<=s; i++) {
v1=i-1; v2=n/i-1;
cv1=0; cv2=0;
if (v1!=0) {
for (int p=1; p<=sqrt(v1); p++) {
cv1+=v1/p-p+1;
}
cv1*=2;
for (int sq=1; sq<=sqrt(v1); sq++) {
cv1--;
}
noc1=((int)(n/(v1+1)))-((int)(n/(v1+2)));
cv1*=noc1; ans+=cv1;
}
if (v2!=0 && v2!=v1) {
for (int p=1; p<=sqrt(v2); p++) {
cv2+=v2/p-p+1;
}
cv2*=2;
for (int sq=1; sq<=sqrt(v2); sq++) {
cv2--;
}
noc2=((int)(n/(v2+1)))-((int)(n/(v2+2)));
cv2*=noc2; ans+=cv2;
}
}
cout<<ans<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3412kb
input:
3 2 5 14
output:
1 9 62
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 2734ms
memory: 3484kb
input:
3 29107867360 65171672278 41641960535
output:
8921593237533 21300450379732 13136180138425
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 4867ms
memory: 3420kb
input:
3 90076809172 100000000000 99913139559
output:
30192292781431 33790187414013 33758574429172
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 4986ms
memory: 3464kb
input:
3 99997992652 99832769119 99997176887
output:
33789456663124 33729325483151 33789159765448
result:
ok 3 lines
Test #5:
score: 0
Accepted
time: 1246ms
memory: 3540kb
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: 447ms
memory: 3484kb
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