好像有一个没写博客,那也不写了
实验四:
扩展欧几里得求同余方程:
Code:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
void exgcd(LL a, LL b, LL& x, LL& y, LL& d)
{
if (b == 0) {
x = 1; y = 0; d = a; return;
}
exgcd(b, a % b, x, y, d);
LL t;
t = x;
x = y;
y = t - (a / b) * y;
}
int main()
{
ios::sync_with_stdio(false);
LL a, b, c;
cin >> a >> b >> c;
LL x, y, d;
exgcd(a, b, x, y, d);
LL g = b / d;
x = x * (c / d);
x = (x % g + g) % g;
cout << x << endl;
return 0;
}
高木同学的因子:
Code:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL gcd(LL a, LL b)
{
if (b == 0) return a;
else return(gcd(b, a % b));
}
int main()
{
LL a, b;
cin >> a >> b;
LL tmp = gcd(a, b);
LL ans = 0;
for (int i = 1; i * i < tmp; i++) {
if (tmp % i == 0) ans += 2;
}
if (pow(sqrt(tmp), 2) == tmp) ans++;
cout << ans << endl;
return 0;
}
费马小定理:
Code:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = 1e9 + 7;
LL ksm(LL a, LL b, LL c)
{
LL ans = 1;
while (b > 0) {
if (b & 1)
{
ans = ans * a % c;
}
b >>= 1;
a = (a * a) % c;
}
return ans;
}
int main()
{
LL a, b, c;
while (cin >> a >> b >> c) {
LL tmp;
tmp = ksm(b, c, MOD - 1);
tmp = ksm(a, tmp, MOD);
cout << tmp << endl;
}
return 0;
}