const int N = 2e5+10; const int M = 500; int cnt, p[N], _gcd[M][M]; int v[N][3],vis[N]; int gcd(int x, int y) { int g = 1; REP(i,0,2) { int tmp; if (v[x][i]>=M) { if (y%v[x][i]==0) tmp = v[x][i]; else tmp = 1; } else tmp = _gcd[y%v[x][i]][v[x][i]]; y…
BZOJ_2242_[SDOI2011]计算器_快速幂+扩展GCD+BSGS 题意: 你被要求设计一个计算器完成以下三项任务: 1.给定y,z,p,计算Y^Z Mod P 的值: 2.给定y,z,p,计算满足xy≡ Z ( mod P )的最小非负整数: 3.给定y,z,p,计算满足Y^x ≡ Z ( mod P)的最小非负整数. 分析: 各种板子题 代码: // luogu-judger-enable-o2 // luogu-judger-enable-o2 #include <std…
You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to ai . Let's denote the function g(x,y) as the greatest common divisor of the numbers written on the vertices belonging to the simple…