# UVA-OJ.关于数论的成长练习

### 1). UVA11582.Colossal Fibonacci Numbers!

#include <cstdio>
#include <cstring>

using namespace std;

typedef unsigned long long ULL;

ULL a, b;
int n, f[1000010];

{
ULL ret = 0; char c = getchar();
while (!(c >= '0' && c <= '9')) c = getchar();
while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
return ret;
}

void init()
{
scanf("%d", &n);
}

ULL mul(ULL a, ULL b, int n)
{
ULL ret = 0;
while (b){
if (b & 1) ret = (ret + a) % n;
a = (2 * a) % n;
b >>= 1;
}
return ret;
}

int power(ULL a, ULL b, int n)
{
ULL ret = 1;
a %= n;
while (b){
if (b & 1) ret = mul(ret, a, n);
a = mul(a, a, n);
b >>= 1;
}
return (int)ret;
}

void doit()
{
int n2 = n * n, r = 2;
f[0] = 0 % n; f[1] = 1 % n;
for (int i = 2; i <= n2; i ++){
f[i] = (f[i - 1] + f[i - 2]) % n;
if (f[i] == f[1] && f[i - 1] == f[0]){
r = i - 1;
break;
}
}
int pos = power(a, b, r);
printf("%d\n", f[pos] % n);
}

int main()
{
int T; scanf("%d", &T);
while (T --){
init();
doit();
}
return 0;
}

### 2).UVA12169.Disgruntled Judge

#include <cstdio>

using namespace std;

const int mod = 10001;
typedef long long LL;

int T;
LL s[10005];

void init()
{
for (int i = 1; i <= T; i ++)
scanf("%lld", &s[(i << 1) - 1]);
}

void ex_gcd(LL a, LL b, LL &d, LL &x, LL &y)
{
if (!b){
x = 1; y = 0; d = a;
return;
} else {
ex_gcd(b, a % b, d, x, y);
int t = x;
x = y; y = t - a / b * x;
}
}

void doit()
{
s[2] = s[1];
if(T >= 2){
for (int a = 0; a <= 10000; a ++){
LL A = a + 1, B = mod, C = s[3] - a * a * s[1];
LL x, y, d;
ex_gcd(A, B, d, x, y);
if (C % d == 0){
x = x * (C / d);
int i;
for (i = 1; i < T; i ++){
s[i << 1] = (s[(i << 1) - 1] * a + x) % mod;
if (s[(i << 1) + 1] != ((s[i << 1] * a + x) % mod)) break;
}
//printf("%d %lld %lld\n", a, x, s[(T << 1) - 1]);
s[T << 1] = (s[(T << 1) - 1] * a + x) % mod;
if (i == T) break;
}
}
}
for (int i = 1; i <= T; i ++) printf("%lld\n", s[i << 1]);
}

int main()
{
while (scanf("%d", &T) != EOF){
init();
doit();
}
return 0;
}

### 3).UVA10375.Choose and divide

#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

const int MAX_N = 10005;

int pri[1500], tot = 0;
bool check[MAX_N];
int p, q, r, s, cnt[1500];

inline void prime()
{
memset(check, 0, sizeof(check));
check[1] = 1;
for (int i = 2; i <= 10000; i ++){
if (!check[i]) pri[++ tot] = i;
for (int j = 1; j <= tot; j ++){
if (i * pri[j] > 10000) break;
check[i * pri[j]] = 1;
if (i % pri[j] == 0) break;
}
}
}

void gao(int x, int d)
{
for (int i = 1; i <= tot; i ++){
while (x % pri[i] == 0){
x /= pri[i];
cnt[i] += d;
}
if (x == 1) break;
}
}

void calc(int n, int d)
{
for (int i = 1; i <= n; i ++)
gao(i, d);
}
void doit()
{
memset(cnt, 0, sizeof(cnt));
calc(p, 1); calc(q, -1); calc(p - q, -1);
calc(s, 1); calc(r - s, 1); calc(r, -1);
double ans = 1.0;
for (int i = 1; i <= tot; i ++)
ans *= pow(pri[i], cnt[i]);
printf("%.5f\n", ans);
}

int main()
{
prime();
while (scanf("%d%d%d%d", &p, &q, &r, &s) != EOF){
doit();
}
return 0;
}

### 4).UVA10791.Minimum Sum LCM

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

const int MAX_N = 1000005;
typedef long long LL;

int p[MAX_N], num[MAX_N], cnt = 0;
LL n;

void doit()
{
cnt = 0;
memset(p, 0, sizeof(p)); memset(num, 0, sizeof(num));
if (n == 1) { printf("2\n"); return; }
if (n == 2147483647) { printf("2147483648\n"); return; }
LL t = n;
for (int i = 2; i * i <= n; i ++){
if (t % i == 0){
p[++ cnt] = i;
while (t % i == 0){
t /= i;
num[cnt] ++;
}
}
if (t == 1) break;
}
if (t != 1) p[++ cnt] = t, num[cnt] ++;
if (cnt == 1) {
LL ans = pow(p[1], num[1]) + 1; printf("%lld\n", ans);
}
else {
LL ans = 0;
for (int i = 1; i <= cnt; i ++){
ans += pow(p[i], num[i]);
}
printf("%lld\n", ans);
}
}

int main()
{
int tot = 0;
while (cin >> n){
if (n == 0) break;
printf("Case %d: ", ++ tot);
doit();
}
return 0;
}

#### 数论 练习题【题解】

2015-08-11 12:57:49

#### NOIP 2016[数论复习]

2016-11-17 20:04:45

#### bzoj-2219 数论之神

2015-08-20 20:02:10

#### ACM 数论知识 合集

2016-08-06 16:50:44

#### 数论练习--日常更新

2017-11-28 17:31:15

#### 几道数论趣题

2015-11-22 19:00:40

#### 数论练习专题

2013-08-25 08:44:05

#### 数论概论学习笔记（一）——勾股数

2016-12-04 15:53:49

#### 【我恨数论】之 斐波那契数列

2016-10-31 09:35:19

#### 数论常用内容——素数

2017-05-04 16:18:33