数学笔记
Vodyanitsaa · · 算法·理论
P15118 [ICPC 2024 LAC] DiviDuelo
发现先手很难赢,于是归纳一下先手能赢的情况:
考虑证明其余情况不能取胜。
若
若
:::info[code]
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define pii pair<int,int>
#define debug(x) cerr<<"debug "<<__LINE__<<":"<<#x<<" = "<<x<<"\n"
#define For(i,a,b) for(int i = a;i<=b;i++)
#define Rof(i,a,b) for(int i = a;i>=b;i--)
inline ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
inline void write(ll x){if(x<0){putchar('-');x=-x;}if(x>9)write(x/10);putchar(x%10+'0');}
using namespace std;
ll n;
bool ck(ll x){
for(ll i = 2;i*i<=x;i++){
if(x%i == 0) return 0;
}
return 1;
}
bool ck2(ll x){
if(!ck(x)) return 0;
int cnt = 0;
ll u = n;
while(u!=1&&u%x == 0){
cnt++;
u/=x;
}
if(u!=1) return 0;
return (cnt%2 == 1);
}
signed main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//std::ios::sync_with_stdio(false);
//std::cin.tie(nullptr);
n = read();
if(n == 1){
putchar('N');
return 0;
}
if(ck(n)){
putchar('Y');
return 0;
}
for(ll i = 2;i*i<=n;i++){
if(n%i == 0){
if(ck2(i)){
putchar('Y');
return 0;
}
if(i!=n/i && ck(i) && ck(n/i)){
putchar('Y');
return 0;
}
}
}
putchar('N');
return 0;
}
:::
Gym105588G GCD
注意到
:::info[code]
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define debug(x) cerr<<"debug "<<__LINE__<<":"<<#x<<" = "<<x<<"\n"
#define For(i,a,b) for(int i = a;i<=b;i++)
#define Rof(i,a,b) for(int i = a;i>=b;i--)
inline ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
inline void write(ll x){if(x<0){putchar('-');x=-x;}if(x>9)write(x/10);putchar(x%10+'0');}
using namespace std;
struct node{
ll x,y,cnt;
};
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//std::ios::sync_with_stdio(false);
//std::cin.tie(nullptr);
int T = read();
while(T--){
ll a = read(),b = read();
queue<node> q;
q.push({a,b,0});
while(!q.empty()){
ll x = q.front().x,y = q.front().y,cnt = q.front().cnt;
q.pop();
if(x == 0 && y == 0){
write(cnt);
putchar('\n');
break;
}
if(x>0) q.push({x-__gcd(x,y),y,cnt+1});
if(y>0) q.push({x,y-__gcd(x,y),cnt+1});
}
while(!q.empty()) q.pop();
}
return 0;
}
:::
欧拉定理
既然有扩展欧拉定理,那先学学欧拉定理吧。
对于整数
扩展欧拉定理
CF906D Power Tower
什么欧拉降幂,等我学学再说。
莫比乌斯反演
作为一个反演,肯定要有原本的函数。
设
即
则莫比乌斯反演用于在已知
莫比乌斯函数
结论
:::info[证明] 等我学学。 :::
替代方法
jxj 的方法:
其中:
::::info[证明]
第一个函数意思就是
考虑
将它们全部化为最简分数后的分母
第二个函数意思就是:
- 当
n = 1 时,\sum\limits_{d|n}\mu(d) = 1 ; - 当
n>1 时,\sum\limits_{d|n}\mu(d) = 0 。
既然有两种情况,那么进行分讨。
-
当
n = 1 时,d = 1 ,所以有\sum\limits_{d|1}\mu(1) = 1 。 -
当
n>1 时,首先看到所有含平方因子的因数d 的莫比乌斯函数值都是0 ,所以直接不管。
然后设
对于集合
:::info[不是很显然]
显然
假设
既然所有无平方因子的因数都可以两两组合,每一组的和都是
P3327 [SDOI2015] 约数个数和
一道纯数学紫。等我看懂了再来写。