Skip to content

Commit e33e987

Browse files
authored
Create GCDEX - GCD Extreme
1 parent 94e59b5 commit e33e987

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
//Author: Fuadul Hasan([email protected])
2+
//BSMRSTU,Gopalganj
3+
//#include<bits/stdc++.h>
4+
#define _USE_MATH_DEFINES
5+
#include <set>
6+
#include <map>
7+
#include <list>
8+
#include <queue>
9+
#include <stack>
10+
#include <cmath>
11+
#include <ctime>
12+
#include <cstdio>
13+
#include <string>
14+
#include <vector>
15+
#include <bitset>
16+
#include <random>
17+
#include <cassert>
18+
#include <cstring>
19+
#include <sstream>
20+
#include <complex>
21+
#include <numeric>
22+
#include <iostream>
23+
#include <algorithm>
24+
#include <functional>
25+
#include <unordered_set>
26+
#include <unordered_map>
27+
using namespace std;
28+
29+
//debug..........
30+
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
31+
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
32+
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
33+
34+
//............ignore it..................//
35+
#define F first
36+
#define S second
37+
38+
#define Pi atan(1)*4
39+
#define mp make_pair
40+
#define pb push_back
41+
const int M = 1e9 + 7;
42+
43+
#define ld long double
44+
#define ll long long int
45+
#define happy cin.tie(0);
46+
47+
#define point(x) cout<<fixed<<setprecision(x)
48+
int length(string s){return (int)s.size();}
49+
50+
#define mem(a) memset(a , 0 ,sizeof a)
51+
#define memn(a) memset(a , -1 ,sizeof a)
52+
53+
#define coding ios::sync_with_stdio(false);
54+
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
55+
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
56+
57+
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}
58+
int dx[8]= {1,0,-1,0,-1,-1,1,1};
59+
int dy[8]= {0,1,0,-1,-1,1,-1,1};
60+
61+
62+
#define rep(i,b,e) for(__typeof(e) i = (b) ; i != (e + 1) - 2 * ((b) > (e)) ; i += 1 - 2 * ((b) > (e)))
63+
64+
long long power(long long a,long long n){ll res = 1;while(n){if(n&1) res = ((res%M)*(a%M))%M;a = ((a%M)*(a%M))%M;n>>=1;}return res%M;}
65+
66+
#define Test cout<<"Case #"<<tc++<<": ";
67+
int tc = 1;
68+
69+
inline void read(std::vector<int> &v){for(int i=0;i<(int)v.size();i++){cin>>(v[i]);}}
70+
inline void readl(std::vector<ll> &v){for(int i=0;i<(int)v.size();i++){cin>>(v[i]);}}
71+
72+
template<class T> bool remin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
73+
template<class T> bool remax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
74+
75+
inline void read(int v[],int n){for(int i=0;i<n;i++){cin>>(v[i]);}}
76+
inline void readl(ll v[],int n){for(int i=0;i<n;i++){cin>>(v[i]);}}
77+
78+
inline int add(int a, int b, int mod) {a += b ; return a >= mod ? a - mod : a ;}
79+
inline int sub(int a, int b, int mod) {a -= b ; return a < 0 ? a + mod : a ;}
80+
inline int mul(int a, int b, int mod) {return (ll)a * b % mod ;}
81+
82+
#define pr pair<int, int>
83+
#define vpr vector<pr>
84+
#define vi std::vector<int>
85+
#define vll std::vector<ll>
86+
#define all(n) n.begin(),n.end()
87+
88+
89+
const int Inf = (int)2e9 + 5;
90+
const ll Lnf = (ll)2e18 + 5;
91+
const int N = 5e5 + 5;
92+
const int NN = 1e6 + 5;
93+
94+
int phi[NN+10];
95+
ll res[NN+10];
96+
97+
void pre_calculation(){
98+
phi[1] = 1;
99+
for(int i=2;i<=NN;i++){
100+
if(phi[i] == 0){
101+
phi[i] = i-1;
102+
for(int j=i+i;j<=NN;j+=i){
103+
if(phi[j] == 0)phi[j] = j;
104+
phi[j] = phi[j] - phi[j]/i;
105+
}
106+
}
107+
}
108+
for(int i=1;i<=NN;i++){
109+
for(int j=i+i; j<=NN;j+=i){
110+
res[j]+= (ll)(i*phi[j/i]);
111+
}
112+
}
113+
114+
for(int i=1;i<NN;i++){
115+
res[i] += res[i-1];
116+
}
117+
}
118+
119+
int solve()
120+
{
121+
122+
//Test
123+
124+
pre_calculation();
125+
int n;
126+
while(cin>>n, n){
127+
cout<<res[n]<<endl;
128+
}
129+
130+
131+
132+
return 0;
133+
//error();
134+
}
135+
int main(){
136+
137+
happy coding
138+
int test = 1;
139+
//cin>>test;
140+
while (test--)solve();return 0;
141+
}
142+
143+
144+

0 commit comments

Comments
 (0)