Last active
May 1, 2021 13:10
-
-
Save hamkewl/b67016d7399b2f0662bfc68183918c21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
submission # - User: hanstick_ | |
https://atcoder.jp/contests/ | |
coding: utf-8 | |
lang: C++ (GCC 9.2.1) | |
*/ | |
#include <bits/stdc++.h> | |
using namespace std; | |
// utility of stdin,stdout | |
#define _CRT_SECURE_NO_WARNINGS | |
#define OUT cout << | |
#define BR << endl | |
#define RET return 0 | |
#define TLong long long | |
#define TBMod int(1e9+7) | |
// fact(n) | |
template <typename T> | |
T fact(T n){ | |
if(n == 1) return 1; | |
else return (n * fact(n - 1)); | |
} | |
// nCr(n, r) | |
template <typename T> | |
T nCr(T n, T r){ | |
if(r == 0 || r == n) return 1; | |
else if(r == 1) return n; | |
return (nCr(n - 1, r - 1) + nCr(n - 1, r)); | |
} | |
// swap(&a, &b); | |
template <typename T> | |
void swap(T *a, T *b){ | |
T tmp; | |
tmp = *a; *a = *b; *b = tmp; | |
return; | |
} | |
// gcd(a, b) | |
template <typename T> | |
T gcd(T a,T b){ | |
if(a == 0) return b; | |
else if(b == 0) return a; | |
else return gcd(b,a % b); | |
} | |
// lcm(a, b) | |
template <typename T> | |
T lcm(T a,T b){ | |
return a / gcd(a,b) * b; | |
} | |
// divisor(type n) | |
template <typename T> | |
vector<T> divisor(T n) | |
{ | |
vector<T> ret; | |
for(T i = 1; i * i <= n; i++) | |
{ | |
if(n % i == 0) { | |
ret.push_back(i); | |
if(i * i != n) ret.push_back(n / i); | |
} | |
} | |
sort(ret.begin(), ret.end()); | |
return ret; | |
} | |
// eratosthenes(type n) | |
template <typename T> | |
vector<T> eratosthenes(T n){ | |
vector<bool> is_prime(n + 2, true); | |
vector<T> primes; | |
for (T i = 2; i <= n; i++) | |
{ | |
if(is_prime[i]){ | |
for (T j = 2 * i; j <= n; j += i) is_prime[j] = false; | |
primes.push_back(i); | |
} | |
} | |
return primes; | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
// DON'T CHANGE | |
cin.tie(0); | |
cout.tie(0); | |
ios::sync_with_stdio(false); | |
// here | |
} |
2020/4/17 updated: use template <typename T>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2020/4/6 modified: fixed coding
lcm(...)
function that may be occured truncation depends on arguments