Codeforces Round #453 (Div. 2) D. GCD of Polynomials 数学构造

本文解析了Codeforces Round #453 (Div.2) D题——GCD of Polynomials,介绍了如何构造两个多项式A(x)和B(x),使其辗转相除恰好进行n次。通过类比斐波那契数列,给出了一种基于递推式的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Codeforces Round #453 (Div. 2)

D. GCD of Polynomials

题意:定义 deg(A(x)) 为多项式 A(x) 的最高项的次数,要你构造两个多项式 A(x), B(x),使得其可辗转相除恰好 n 次,即 { A(x), B(x) } -> { B(x), A(x)%B(x) } .........

tags:做不来这种构造题啊,,,但又确实是个好题,长见识了 *-*

很容易看出,要恰好 n 次,那 deg(A(x)) 肯定是 n, deg(B(x)) 肯定是 n-1。

然后类似 Fibonacci数列,{ f(n+1), f(n) }  ->   { f(n), f(n-1) }  ->  { f(n-1), f(n-2) } ......

递推式是 f(n+1) = x*f(n) + f(n-1)   %2 。

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define rep(i,a,b) for (int i=a; i<=b; ++i)
#define per(i,b,a) for (int i=b; i>=a; --i)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define fi  first
#define se  second
typedef long long ll;
const int N = 200005;

int n, a[200][200];
int main()
{
    scanf("%d", &n);
    a[1][1]=1;
    a[2][1]=0, a[2][2]=1;
    rep(i,3,n+1)
    {
        rep(j,2,i)
            a[i][j] = a[i-1][j-1];
        rep(j,1,i)
            ( a[i][j] += a[i-2][j] ) %=2;
    }
    printf("%d\n", n);
    rep(j,1,n+1)
        printf("%d%c", a[n+1][j], " \n"[j==n+1]);
    printf("%d\n", n-1);
    rep(j,1,n)
        printf("%d ", a[n][j]);

    return 0;
}

转载于:https://www.cnblogs.com/sbfhy/p/8179630.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值