[Codeforces 225E] Unsolvable (向下取整+梅森质数)

本文解析了Codeforces-225E题目的解题思路,通过数学推导,给出了方程z=[x/2]+y+xy无正整数解的条件,并提供了AC代码。

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

Codeforces - 225E

正整数 z,使得方程
z = [x/2]+y+xy 没有正整数解


数论好题!
首先显然要把向下取整的去掉
x=2k+1 (k0)
z=k+2y+2ky
z=k+2y(k+1)
z+1=(2y+1)(k+1) (k0)
由此可以看出,对于任何 z+1含奇质因子的都能构造出解,
所以要想无解,z+1=2t,即 z=2t1

x=2k (k>0)
z=k+y+2ky
2z+1=2k+2y+4ky+1
2z+1=(2y+1)(2k+1) (k>0)
2t+11=(2y+1)(2k+1)
所以除非 2t+11是个质数,否则都能构造出解
形如 2n1的质数是梅森质数,目前找到了 49个梅森质数
题目只要求前 40个,百度一下就找到了。

#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
using namespace std;
typedef pair<int,int> Pii;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DBL;
typedef long double LDBL;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define SQR(a) ((a)*(a))
#define PCUT puts("\n----------")

const int MOD=1e9+7;
int N;
int tp[50]={0, 2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433, 1257787, 1398269, 2976221, 3021377, 6972593, 13466917, 20996011, 24036583, 25964951, 30402457, 32582657};
LL Pow(LL,LL,LL);

int main()
{
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
    #endif

    while(~scanf("%d", &N))
    {
        printf("%d\n", (int)(Pow(2,tp[N]-1,MOD)-1+MOD)%MOD);
    }
    return 0;
}

LL Pow(LL x, LL n, LL p)
{
    LL res=1;
    while(n)
    {
        if(n&1) res=res*x%p;
        x=x*x%p;
        n>>=1;
    }
    return res;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值