读入 并查集 gcd/exgcd 高精度 快速幂
ios_base::sync_with_stdio();
cin.tie();
int to[MAXM << ], nxt[MAXM << ], Head[MAXN], ed = ;
inline void addedge(int u, int v)
{
to[++ed] = v;
nxt[ed] = Head[u];
Head[u] = ed;
}
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
//睿智OJ头文件
CLOCK
printf("Time: %.3lfs\n", (double)clock() / CLOCKS_PER_SEC);
枚举子集
for (int sub = (j - )&j; sub; sub = (sub - )&j)
Huyyt
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + ;
const int gakki = + + + + 1e9;
const int MAXN = 2e5 + ;
const int MAXM = 2e5 + ;
int main()
{
ios_base::sync_with_stdio();
cin.tie();
return ;
}
读入挂
template <typename T> inline void read(T&x)
{
char cu = getchar();
x = ;
bool fla = ;
while (!isdigit(cu))
{
if (cu == '-')
{
fla = ;
}
cu = getchar();
}
while (isdigit(cu))
{
x = x * + cu - '', cu = getchar();
}
if (fla)
{
x = -x;
}
}
inline void read(int &v)
{
v = ;
char c = ;
int p = ;
while (c < '' || c > '')
{
if (c == '-')
{
p = -;
}
c = getchar();
}
while (c >= '' && c <= '')
{
v = (v << ) + (v << ) + c - '';
c = getchar();
}
v *= p;
}
输出挂
struct Quick_Out {
char buf[BUFFER_MAX_SIZE], *ps = buf, *pe = buf + BUFFER_MAX_SIZE;
char tmp[];
double dx[] = {5e-,5e-,5e-,5e-,5e-,5e-,5e-,5e-,5e-,5e-,5e-,5e-,5e-,5e-,5e-};
inline void write() {
fwrite(buf, sizeof(char), ps - buf, stdout);
ps = buf;
}
inline void oc(char c) {
*(ps++) = c;
if (ps == pe) write();
}
inline void os(char *s) {
for (int i = ; s[i]; ++i) oc(s[i]);
}
template<class T>
inline void oi(T x, char bc = '\n') {
if (x < ) oc('-'), x = -x;
int len = ;
if (!x) tmp[len++] = '';
while (x) tmp[len++] = x % + '', x /= ;
while (len) oc(tmp[--len]);
oc(bc);
}
~Quick_Out() {
write();
}
} Out;
并查集
int par[maxn], hs[maxn],int sz[maxn];
int cnt;
void init(int n)
{
for (int i = ; i <= n; i++)
{
par[i] = i, hs[i] = i, sz[i] = ;
}
}
int find(int x)
{
return par[x] == x ? x : par[x] = find(par[x]);
}
void unite(int x, int y)
{
x = find(x);
y = find(y);
if (x != y)
{
par[x] = y, sz[y] += sz[x];
}
}
void del(int x)
{
sz[find(hs[x])]--;
hs[x] = ++cnt;
}
高精度
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 3e7 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll mod = 1e6;
using namespace std;
const int base = ;
const int base_digits = ;
struct bigint
{
vector<int> a;
int sign;
int size()
{
if (a.empty())
{
return ;
}
int ans = (a.size() - ) * base_digits;
int ca = a.back();
while (ca)
{
ans++, ca /= ;
}
return ans;
}
bigint operator ^(const bigint &v)
{
bigint ans = , a = *this, b = v;
while (!b.isZero())
{
if (b % )
{
ans *= a;
}
a *= a, b /= ;
}
return ans;
}
bigint() :
sign()
{
} bigint(long long v)
{
*this = v;
} bigint(const string &s)
{
read(s);
} void operator=(const bigint &v)
{
sign = v.sign;
a = v.a;
} void operator=(long long v)
{
sign = ;
if (v < )
{
sign = -, v = -v;
}
for (; v > ; v = v / base)
{
a.push_back(v % base);
}
} bigint operator+(const bigint &v) const
{
if (sign == v.sign)
{
bigint res = v; for (int i = , carry = ; i < (int) max(a.size(), v.a.size()) || carry; ++i)
{
if (i == (int) res.a.size())
{
res.a.push_back();
}
res.a[i] += carry + (i < (int) a.size() ? a[i] : );
carry = res.a[i] >= base;
if (carry)
{
res.a[i] -= base;
}
}
return res;
}
return *this - (-v);
} bigint operator-(const bigint &v) const
{
if (sign == v.sign)
{
if (abs() >= v.abs())
{
bigint res = *this;
for (int i = , carry = ; i < (int) v.a.size() || carry; ++i)
{
res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : );
carry = res.a[i] < ;
if (carry)
{
res.a[i] += base;
}
}
res.trim();
return res;
}
return -(v - *this);
}
return *this + (-v);
} void operator*=(int v)
{
if (v < )
{
sign = -sign, v = -v;
}
for (int i = , carry = ; i < (int) a.size() || carry; ++i)
{
if (i == (int) a.size())
{
a.push_back();
}
long long cur = a[i] * (long long) v + carry;
carry = (int) (cur / base);
a[i] = (int) (cur % base);
}
trim();
} bigint operator*(int v) const
{
bigint res = *this;
res *= v;
return res;
} friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1)
{
int norm = base / (b1.a.back() + );
bigint a = a1.abs() * norm;
bigint b = b1.abs() * norm;
bigint q, r;
q.a.resize(a.a.size()); for (int i = a.a.size() - ; i >= ; i--)
{
r *= base;
r += a.a[i];
int s1 = r.a.size() <= b.a.size() ? : r.a[b.a.size()];
int s2 = r.a.size() <= b.a.size() - ? : r.a[b.a.size() - ];
int d = ((long long) base * s1 + s2) / b.a.back();
r -= b * d;
while (r < )
{
r += b, --d;
}
q.a[i] = d;
} q.sign = a1.sign * b1.sign;
r.sign = a1.sign;
q.trim();
r.trim();
return make_pair(q, r / norm);
} bigint operator/(const bigint &v) const
{
return divmod(*this, v).first;
} bigint operator%(const bigint &v) const
{
return divmod(*this, v).second;
} void operator/=(int v)
{
if (v < )
{
sign = -sign, v = -v;
}
for (int i = (int) a.size() - , rem = ; i >= ; --i)
{
long long cur = a[i] + rem * (long long) base;
a[i] = (int) (cur / v);
rem = (int) (cur % v);
}
trim();
} bigint operator/(int v) const
{
bigint res = *this;
res /= v;
return res;
} int operator%(int v) const
{
if (v < )
{
v = -v;
}
int m = ;
for (int i = a.size() - ; i >= ; --i)
{
m = (a[i] + m * (long long) base) % v;
}
return m * sign;
} void operator+=(const bigint &v)
{
*this = *this + v;
}
void operator-=(const bigint &v)
{
*this = *this - v;
}
void operator*=(const bigint &v)
{
*this = *this * v;
}
void operator/=(const bigint &v)
{
*this = *this / v;
} bool operator<(const bigint &v) const
{
if (sign != v.sign)
{
return sign < v.sign;
}
if (a.size() != v.a.size())
{
return a.size() * sign < v.a.size() * v.sign;
}
for (int i = a.size() - ; i >= ; i--)
if (a[i] != v.a[i])
{
return a[i] * sign < v.a[i] * sign;
}
return false;
} bool operator>(const bigint &v) const
{
return v < *this;
}
bool operator<=(const bigint &v) const
{
return !(v < *this);
}
bool operator>=(const bigint &v) const
{
return !(*this < v);
}
bool operator==(const bigint &v) const
{
return !(*this < v) && !(v < *this);
}
bool operator!=(const bigint &v) const
{
return *this < v || v < *this;
} void trim()
{
while (!a.empty() && !a.back())
{
a.pop_back();
}
if (a.empty())
{
sign = ;
}
} bool isZero() const
{
return a.empty() || (a.size() == && !a[]);
} bigint operator-() const
{
bigint res = *this;
res.sign = -sign;
return res;
} bigint abs() const
{
bigint res = *this;
res.sign *= res.sign;
return res;
} long long longValue() const
{
long long res = ;
for (int i = a.size() - ; i >= ; i--)
{
res = res * base + a[i];
}
return res * sign;
} friend bigint gcd(const bigint &a, const bigint &b)
{
return b.isZero() ? a : gcd(b, a % b);
}
friend bigint lcm(const bigint &a, const bigint &b)
{
return a / gcd(a, b) * b;
} void read(const string &s)
{
sign = ;
a.clear();
int pos = ;
while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+'))
{
if (s[pos] == '-')
{
sign = -sign;
}
++pos;
}
for (int i = s.size() - ; i >= pos; i -= base_digits)
{
int x = ;
for (int j = max(pos, i - base_digits + ); j <= i; j++)
{
x = x * + s[j] - '';
}
a.push_back(x);
}
trim();
} friend istream& operator>>(istream &stream, bigint &v)
{
string s;
stream >> s;
v.read(s);
return stream;
} friend ostream& operator<<(ostream &stream, const bigint &v)
{
if (v.sign == -)
{
stream << '-';
}
stream << (v.a.empty() ? : v.a.back());
for (int i = (int) v.a.size() - ; i >= ; --i)
{
stream << setw(base_digits) << setfill('') << v.a[i];
}
return stream;
} static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits)
{
vector<long long> p(max(old_digits, new_digits) + );
p[] = ;
for (int i = ; i < (int) p.size(); i++)
{
p[i] = p[i - ] * ;
}
vector<int> res;
long long cur = ;
int cur_digits = ;
for (int i = ; i < (int) a.size(); i++)
{
cur += a[i] * p[cur_digits];
cur_digits += old_digits;
while (cur_digits >= new_digits)
{
res.push_back(int(cur % p[new_digits]));
cur /= p[new_digits];
cur_digits -= new_digits;
}
}
res.push_back((int) cur);
while (!res.empty() && !res.back())
{
res.pop_back();
}
return res;
} typedef vector<long long> vll; static vll karatsubaMultiply(const vll &a, const vll &b)
{
int n = a.size();
vll res(n + n);
if (n <= )
{
for (int i = ; i < n; i++)
for (int j = ; j < n; j++)
{
res[i + j] += a[i] * b[j];
}
return res;
} int k = n >> ;
vll a1(a.begin(), a.begin() + k);
vll a2(a.begin() + k, a.end());
vll b1(b.begin(), b.begin() + k);
vll b2(b.begin() + k, b.end()); vll a1b1 = karatsubaMultiply(a1, b1);
vll a2b2 = karatsubaMultiply(a2, b2); for (int i = ; i < k; i++)
{
a2[i] += a1[i];
}
for (int i = ; i < k; i++)
{
b2[i] += b1[i];
} vll r = karatsubaMultiply(a2, b2);
for (int i = ; i < (int) a1b1.size(); i++)
{
r[i] -= a1b1[i];
}
for (int i = ; i < (int) a2b2.size(); i++)
{
r[i] -= a2b2[i];
} for (int i = ; i < (int) r.size(); i++)
{
res[i + k] += r[i];
}
for (int i = ; i < (int) a1b1.size(); i++)
{
res[i] += a1b1[i];
}
for (int i = ; i < (int) a2b2.size(); i++)
{
res[i + n] += a2b2[i];
}
return res;
} bigint operator*(const bigint &v) const
{
vector<int> a6 = convert_base(this->a, base_digits, );
vector<int> b6 = convert_base(v.a, base_digits, );
vll a(a6.begin(), a6.end());
vll b(b6.begin(), b6.end());
while (a.size() < b.size())
{
a.push_back();
}
while (b.size() < a.size())
{
b.push_back();
}
while (a.size() & (a.size() - ))
{
a.push_back(), b.push_back();
}
vll c = karatsubaMultiply(a, b);
bigint res;
res.sign = sign * v.sign;
for (int i = , carry = ; i < (int) c.size(); i++)
{
long long cur = c[i] + carry;
res.a.push_back((int) (cur % ));
carry = (int) (cur / );
}
res.a = convert_base(res.a, , base_digits);
res.trim();
return res;
}
}; int main()
{
bigint anser;
int n;
cin >> n;
bigint N(n);
if (n & )
{
anser = (N - bigint()) * (N - bigint()) * (bigint() * N * N * N * N - bigint() * N * N * N + bigint() * N * N - bigint() * N + bigint()) / bigint();
}
else
{
anser = N * (N - bigint()) * (N - bigint()) * (bigint() * N * N * N - bigint() * N * N + bigint() * N - bigint()) / bigint();
}
cout << anser << endl;
return ;
}
GCD
ll gcd(ll a, ll b){
ll t;
while(b){
t = b;
b = a % b;
a = t;
}
return a;
}
EXGCD
ll exgcd(ll a,ll b,ll &x,ll &y){
if (!b){
x=,y=;
return a;
}
ll res=exgcd(b,a%b,y,x);
y-=(a/b)*x;
return res;
}
快速幂
ll Qpow(ll a, ll b)
{
ll ans = , base = a;
while (b != )
{
if (b & != )
{
ans *= base;
ans %= mod;
}
base *= base;
base %= mod;
b >>= 1LL;
}
return ans;
}
组合数
ll ncr(ll n, ll r)
{
if (r < || n < )
{
return ;
}
if (n < r)
{
return ;
}
ll a = fact[n];
a = (a * Invfact[r]) % mod;
a = (a * Invfact[n - r]) % mod;
return a;
}
线性逆元
inv[i] = (p - p / i) * inv[p % i] % p;
方向
int dir[][] = { , -, -, , , , , };
__Int128
inline __int128 read(){
__int128 x=,f=;
char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')
f=-;
ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';
ch=getchar();
}
return x*f;
} inline void print(__int128 x){
if(x<){
putchar('-');
x=-x;
}
if(x>)
print(x/);
putchar(x%+'');
} int main(void){
__int128 a = read();
__int128 b = read();
print(a + b);
cout<<endl;
return ;
}
Hash
int hs = ;
for (int i = ; i <= ; i++)
{
hs = (233LL * hs % mod + s[i]) % mod;
}
读入 并查集 gcd/exgcd 高精度 快速幂的更多相关文章
- hdu 2462(欧拉定理+高精度快速幂模)
The Luckiest number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 5187(高精度快速幂)
zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 洛谷试炼场-简单数学问题-P1045 麦森数-高精度快速幂
洛谷试炼场-简单数学问题 B--P1045 麦森数 Description 形如2^P−1的素数称为麦森数,这时P一定也是个素数.但反过来不一定,即如果PP是个素数,2^P-1 不一定也是素数.到19 ...
- Qbxt 模拟赛 Day4 T2 gcd(矩阵乘法快速幂)
/* 矩阵乘法+快速幂. 一开始迷之题意.. 这个gcd有个规律. a b b c=a*x+b(x为常数). 然后要使b+c最小的话. 那x就等于1咯. 那么问题转化为求 a b b a+b 就是斐波 ...
- GCD&&素筛&&快速幂 --A - Pseudoprime numbers
Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a (mod p). Th ...
- hzau 1202 GCD(矩阵快速幂)
1202: GCD Time Limit: 1 Sec Memory Limit: 1280 MBSubmit: 201 Solved: 31[Submit][Status][Web Board] ...
- HDU 4704 Sum (高精度+快速幂+费马小定理+二项式定理)
Sum Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64u Submit Status ...
- a^b-b^a - SGU 112(高精度快速幂)
分析:直接上吧,建议不要使用模板,否则没啥意义了. 代码如下: ==================================================================== ...
- 高精度快速幂(Java版)
import java.io.*; import java.math.*; import java.util.*; import java.text.*; public class Main { pu ...
随机推荐
- CTF 资源
1.<CTF 工具集>包括web工具.渗透环境.隐形工具.逆向工具.漏洞扫描工具.sql注入工具.暴力破解工具.加解密工具等等. 参考地址:https://www.ctftools.com ...
- web端自动化——Python的smtplib发送电子邮件
SMTP (Simple Mail Transfer Protocol)是简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式. Python的smtplib模块提 ...
- mycat搭建环境
macos完全卸载mysql: https://blog.csdn.net/u012721519/article/details/55002626 踩过的坑: mycat1.6不支持单库分表; 最少要 ...
- 由于我最近搞了个wordpress搭建博客,这里我为大家分享一哈,使用wordpress过程中遇到的坑
Windows server下搭建mysql+php+apache环境参考教程: https://blog.csdn.net/qq_38125058/article/details/81157865 ...
- htm5 css学习笔记整理
点击链接后退页面: <a href="javascript:history.go(-1)">回到上一个网页</a> ——修改placeholder提示的样式 ...
- java绘图(基于Graphics2D)
1.绘图基本操作 请参考下面基础示例: int width = 200, height = 250; //创建图片对象 BufferedImage image = new BufferedImage( ...
- [转帖]Linux运维工程师的十个基本技能点
Linux运维工程师的十个基本技能点 https://cloud.tencent.com/developer/article/1115068 本人是Linux运维工程师,对这方面有点心得,现在我说 ...
- TypeScript tsconfig.json(TypeScript配置)
如果一个目录下存在一个tsconfig.json文件,那么意味着这个目录是TypeScript项目的根目录. tsconfig.json文件中指定了用来编译这个项目的根文件和编译选项. 一个项目可以通 ...
- (十七)springMvc 对表单提交的日期以及JSON中的日期的参数绑定
文章目录 前言 `Ajax`提交表单数据 `Ajax`提交`JSON` 格式数据 解决输出JSON乱码的问题 控制JSON输出日期格式 小记 前言 springMVC 提供强大的参数绑定功能,使得我们 ...
- python 之 面向对象基础(继承与派生,经典类与新式类)
7.2 继承与派生 7.21继承 1.什么是继承? 继承是一种新建类的的方式,在python中支持一个子类继承多个父类.新建的类称为子类或者派生类,父类又可以称为基类或者超类,子类会”遗传“父类的属性 ...