Visit of the Great

本文提供了一道关于数论中最小公倍数和最大公约数计算的复杂问题的解答过程,通过对数学公式和算法的推导,给出了求解特定形式表达式的有效方法。

1.前言

真好玩,蛤蛤蛤蛤蛤蛤蛤蛤蛤蛤蛤蛤蛤蛤蛤蛤蛤蛤蛤

2.题解

令G(x)={1,2∣x2,2∤xgcd(k2i+1,k2i+1+1)=gcd(k2i+1,k2i+1−k2i)=gcd(k2i+1,k2i×(k2i−1))=gcd(k2i+1,k2i−1)=gcd((k2i+1)−(k2i−1),k2i−1)=gcd(2,k2i−1)=G(k)\begin{aligned}令 G (x) = \begin{cases} 1, 2 \mid x \\ 2, 2 \nmid x \end{cases}\\gcd (k^{2^{i}} + 1, k^{2^{i + 1}} + 1) &= gcd (k^{2^{i}} + 1, k^{2^{i + 1}} - k^{2^{i}})\\&= gcd (k^{2^{i}} + 1, k^{2^{i}} \times (k^{2^{i}} - 1))\\&= gcd (k^{2^{i}} + 1, k^{2^{i}} - 1)\\&= gcd ((k^{2^{i}} + 1) - (k^{2^{i}} - 1), k^{2^{i}} - 1)\\&= gcd (2, k^{2^{i}} - 1)\\&= G (k)\end{aligned}G(x)={1,2x2,2xgcd(k2i+1,k2i+1+1)=gcd(k2i+1,k2i+1k2i)=gcd(k2i+1,k2i×(k2i1))=gcd(k2i+1,k2i1)=gcd((k2i+1)(k2i1),k2i1)=gcd(2,k2i1)=G(k)

lcmi=lr(k2i+1) mod p=lcm(lcmi=lr−2(k2i+1),(k2r−1+1)×(k2r+1)gcd(k2r−1+1,k2r+1))=lcm(lcmi=lr−2(k2i+1),(k2r−1+1)×(k2r+1)G(k))=lcm(lcmi=lr−3(k2i+1),(k2r−2+1)×(k2r−1+1)×(k2r+1)G(k)×G(k))=...\begin{aligned}\mathrm{lcm}_{i = l}^{r} (k^{2^{i}} + 1) \bmod p &= lcm (lcm_{i = l}^{{r - 2}} (k^{2^{i}} + 1), \frac{(k^{2^{r - 1}} + 1) \times (k^{2^{r}} + 1)}{gcd (k^{2^{r - 1}} + 1, k^{2^{r}} + 1)} )\\&= lcm (lcm_{i = l}^{{r - 2}} (k^{2^{i}} + 1), \frac{(k^{2^{r - 1}} + 1) \times (k^{2^{r}} + 1)}{G (k)} )\\&= lcm (lcm_{i = l}^{{r - 3}} (k^{2^{i}} + 1), \frac{(k^{2^{r - 2}} + 1) \times (k^{2^{r - 1}} + 1) \times (k^{2^{r}} + 1)}{G (k) \times G (k)} ) \\ &=... \end{aligned}lcmi=lr(k2i+1)modp=lcm(lcmi=lr2(k2i+1),gcd(k2r1+1,k2r+1)(k2r1+1)×(k2r+1))=lcm(lcmi=lr2(k2i+1),G(k)(k2r1+1)×(k2r+1))=lcm(lcmi=lr3(k2i+1),G(k)×G(k)(k2r2+1)×(k2r1+1)×(k2r+1))=...

lcmi=lr(k2i+1) mod p=∏i=lr(k2i+1)G(K)r−l mod p=∏i=lr(k2i+1)Gr−l(K) mod p\begin{aligned}\mathrm{lcm}_{i = l}^{r} (k^{2^{i}} + 1) \bmod p &= \frac{\prod_{i = l}^{r} (k^{2^{i}} + 1)}{G(K)^{r - l}} \bmod p\\&= \frac{\prod_{i = l}^{r} (k^{2^{i}} + 1)}{G^{r - l}(K)} \bmod p\end{aligned}lcmi=lr(k2i+1)modp=G(K)rli=lr(k2i+1)modp=Grl(K)i=lr(k2i+1)modp

发现这个小东西 ∏i=lr((k2l)i−l+1)\prod_{i = l}^{r} ((k^{2^{l}})^{i - l} + 1)i=lr((k2l)il+1) 就是 ∑i=0r=2r−l+1−1(k2l)i\sum\limits_{i = 0}^{r = 2^{r - l + 1} - 1} (k^{2^{l}})^ii=0r=2rl+11(k2l)i (二进制拆分的唯一性)
(k2l)2r−l+1−1k2l−1=k2r+1−1k2l−1\begin{aligned} \frac{(k^{2^{l}})^{2^{r - l + 1}} - 1}{k^{2^{l}} - 1}\\= \frac{k^{2^{r + 1}} - 1}{k^{2^{l}} - 1}\end{aligned}k2l1(k2l)2rl+11=k2l1k2r+11

lcmi=lr(k2i+1) mod p=k2r+1−1(k2l−1)×Gr−l(K)\begin{aligned}\mathrm{lcm}_{i = l}^{r} (k^{2^{i}} + 1) \bmod p &= \frac{k^{2^{r + 1}} - 1}{(k^{2^{l}} - 1) \times G^{r - l}(K)}\end{aligned}lcmi=lr(k2i+1)modp=(k2l1)×Grl(K)k2r+11

然后有一个很 ?? 的 ?? 特判, k mod p==0k \bmod p == 0kmodp==0 时要搞很多奇怪的东西,去 ? 好了。

因为当 k mod p==0k \bmod p == 0kmodp==0 时, 2r+1 mod (p−1)2^{r + 1} \bmod (p - 1)2r+1mod(p1) 如果为零,则它会算出来一个 k0 mod p=1k ^ 0 \bmod p = 1k0modp=1,所以不对,这时候改为返回值为 000 就好了。

#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define fi first
#define se second
#define db double
#define LL long long
#define ULL unsigned long long
#define PII pair <int, int>
#define MP(x,y) make_pair (x, y)
#define rep(i,j,k) for (int i = (j); i <= (k); ++i)
#define per(i,j,k) for (int i = (j); i >= (k); --i)

template <typename T> T Max (T x, T y) { return x > y ? x : y; }
template <typename T> T Min (T x, T y) { return x < y ? x : y; }
template <typename T> T Abs (T x) { return x > 0 ? x : -x; }
template <typename T>
void read (T &x) {
    x = 0; T f = 1;
    char ch = getchar ();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar ();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + ch - '0';
        ch = getchar ();
    }
    x *= f;
}
template <typename T, typename... Args>
void read (T &x, Args&... args) {
    read (x); read (args...);
}
char For_Print[25];
template <typename T>
void write (T x) {
    if (x == 0) { putchar ('0'); return; }
    if (x < 0) { putchar ('-'); x = -x; }
    int poi = 0;
    while (x) {
        For_Print[++poi] = x % 10 + '0';
        x /= 10;
    }
    while (poi) putchar (For_Print[poi--]);
}
template <typename T>
void print (T x, char ch) {
    write (x); putchar (ch);
}

const LL Mod = 1e9 + 7;

LL sqre (LL x) { return x * x % Mod; }
void del (LL &x, LL y) { ((x -= y) < 0) && (x += Mod); }
void add (LL &x, LL y) { ((x += y) >= Mod) && (x -= Mod); }

LL t, k, l, r, p;

LL quick_pow (LL x, LL y, LL M) {
    LL res = 1;
    while (y) {
        if (y & 1) res = (res * x) % M;
        x = (x * x) % M; y >>= 1;
    }
    return res;
}
LL inv (LL x, LL M) {
    return quick_pow (x, M - 2, M);
}
LL G (LL x) {
    return (x % 2 == 0 ? 1 : 2);
}
LL f (LL x) {
	return k % p == 0 ? 0 : quick_pow (k, quick_pow (2, x, p - 1), p);
}

int main () {
    // freopen ("D:\\lihan\\1.in", "r", stdin);
    // freopen ("D:\\lihan\\1.out", "w", stdout);
    read (t);
    while (t--) {
        read (k, l, r, p);
        
		if (p == 2) {
			printf ("%d\n", (k % 2 == 1 ? 0 : 1));
			continue;
		}
		
        LL res = 0;
		if (f (l) == 1) {
			res = quick_pow (2, r - l + 1, p);
		}
		else {
			
//			printf ("f (r + 1) = %lld, f (l) = %lld\n", f (r + 1), f (l));
			
			res = f (r + 1) - 1 + p;
			res = (res * inv (f (l) - 1 + p, p)) % p;
		}
		
//		cout << res << endl;
		
        res *= inv (quick_pow (G (k), r - l, p) % p, p);
        res = (res % p + p) % p;
        print (res, '\n');
    }
    return 0;
}

3.一些编辑很久的错误式子,pi用没有😓,下次我就要用这个出题 /wx

gcdi=lr(k2i+1) mod p=gcd((k2l+1),gcdi=l+1r((k2i+1)−(k2i−1+1))) mod p=gcd((k2l+1),gcdi=l+1r(k2i−k2i−1)) mod p=gcd((k2l+1),gcdi=l+1r(k2i−1⋅2−k2i−1)) mod p=gcd((k2l+1),gcdi=l+1r(k2i−1×k2i−1−k2i−1)) mod p=gcd((k2l+1),gcdi=l+1r(k2i−1×(k2i−1−1))) mod p=gcd((k2l+1),k2l⋅gcdi=l+1r(k2i−1−1)) mod p=gcd((k2l+1),gcdi=lr−1(k2i−1)) mod p\begin{aligned}\mathrm{gcd}_{i = l}^{r} (k^{2^{i}} + 1) \bmod p &= gcd \bigg( (k^{2^{l}} + 1), \mathrm{gcd}_{i = l + 1}^{r} \Big( (k^{2^{i}} + 1) - (k^{2^{i - 1}} + 1) \Big) \bigg) \bmod p\\&= gcd \bigg( (k^{2^{l}} + 1), \mathrm{gcd}_{i = l + 1}^{r} \Big( k^{2^{i}} - k^{2^{i - 1}} \Big) \bigg) \bmod p\\&= gcd \bigg( (k^{2^{l}} + 1), \mathrm{gcd}_{i = l + 1}^{r} \Big( k^{2^{i - 1} \cdot 2} - k^{2^{i - 1}} \Big) \bigg) \bmod p\\&= gcd \bigg( (k^{2^{l}} + 1), \mathrm{gcd}_{i = l + 1}^{r} \Big( k^{2^{i - 1}} \times k^{2^{i - 1}} - k^{2^{i - 1}} \Big) \bigg) \bmod p \\&= gcd \bigg( (k^{2^{l}} + 1), \mathrm{gcd}_{i = l + 1}^{r} \Big( k^{2^{i - 1}} \times (k^{2^{i - 1}} - 1) \Big) \bigg) \bmod p\\&= gcd \bigg( (k^{2^{l}} + 1), k^{2^{l}} \cdot \mathrm{gcd}_{i = l + 1}^{r} \Big( k^{2^{i - 1}} - 1 \Big) \bigg) \bmod p\\&= gcd \bigg( (k^{2^{l}} + 1), \mathrm{gcd}_{i = l}^{r - 1} \Big( k^{2^{i}} - 1 \Big) \bigg) \bmod p\end{aligned}gcdi=lr(k2i+1)modp=gcd((k2l+1),gcdi=l+1r((k2i+1)(k2i1+1)))modp=gcd((k2l+1),gcdi=l+1r(k2ik2i1))modp=gcd((k2l+1),gcdi=l+1r(k2i12k2i1))modp=gcd((k2l+1),gcdi=l+1r(k2i1×k2i1k2i1))modp=gcd((k2l+1),gcdi=l+1r(k2i1×(k2i11)))modp=gcd((k2l+1),k2lgcdi=l+1r(k2i11))modp=gcd((k2l+1),gcdi=lr1(k2i1))modp

gcdi=lr(k2i−1)=gcd(k2l−1,gcdi=l+1r(k2i−k2i−1)) mod p=gcd(k2l−1,k2l⋅gcdi=lr−1(k2i−1)) mod p=(k2l−1) mod p\begin{aligned}\mathrm{gcd}_{i = l}^{r} \Big( k^{2^{i}} - 1 \Big)&= gcd \Big( k^{2^{l}} - 1, \mathrm{gcd}_{i = l + 1}^{r} (k^{2^{i}} - k^{2^{i - 1}}) \Big) \bmod p\\&= gcd \Big( k^{2^{l}} - 1, k^{2^{l}} \cdot \mathrm{gcd}_{i = l}^{r - 1} (k^{2^{i}} - 1) \Big) \bmod p\\&= (k^{2^{l}} - 1) \bmod p\end{aligned}gcdi=lr(k2i1)=gcd(k2l1,gcdi=l+1r(k2ik2i1))modp=gcd(k2l1,k2lgcdi=lr1(k2i1))modp=(k2l1)modp

所以原式可以化为

gcdi=lr(k2i+1) mod p=gcd((k2l+1),(k2l−1)) mod p\begin{aligned}\mathrm{gcd}_{i = l}^{r} (k^{2^{i}} + 1) \bmod p &= gcd ((k^{2^{l}} + 1), (k^{2^{l}} - 1)) \bmod p\end{aligned}gcdi=lr(k2i+1)modp=gcd((k2l+1),(k2l1))modp

阅读下面材料,在空格处填入适当的内容(1个单词)或使用括号中单词的正确形式。 If including inter-state sections, those not protecting the northern border of China, the oldest _____56____(exist) section of the Great Wall of China was the Qi State "Great Wall". It stretches for over 500 kilometers (300 miles) from the Yellow River at Jinan eastwards to the East China Sea, almost ___57____(divide) Shandong Province in half. The "Great Wall" of the Qi State was ___58____(initial) built around 650 BC, and expended during the Warring States Period (475–221 BC). Before the Qi State Wall was built, natural barriers, i.e. rivers and mountain ranges, formed ____59_____ only defensible boundaries between territories as barriers ___60____ enemies. The State of Qi built its Great-Wall-esque military barrier along its southern border to prevent attacks from the State of Lu and the State of Chu. However, rapid development and ____61____(construct) have brought many new problems and challenges in protecting the wall. ____62____ is necessary to provide a solid legal guarantee for its conservation. To tackle the challenges, Shandong Province has passed a regulation protecting the structure____63____will take effect on Jan. 1. This year, Shandong has added 860 patrol posts in seven cities along the Qi wall, mainly recruiting farmers living nearby. Guo Jialian has been patrolling the section of the wall in Guangli village for three months. "I need to check ____64______ there is any damage to the wall that is caused by people digging earth from it. Awareness of protecting the Qi wall _____65_____ (enhance) in recent years. We all know the wall is a cultural relic," says Guo, adding that he frequently sees tourists coming to visit the ancient structure.
02-06
评论 11
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值