BZOJ 2721 Violet 5 樱花 数论

题目大意:给定n,求有多少正整数数对(x,y)满足1x+1y=1n!

由于x,y>0,故显然有y>n!

不妨设y=n!+t(t>0),那么有

1x+1n!+t=1n!

化简后得到

n!(n!+t)+x(n!)=x(n!+t)

x=(n!)2t+n!

故答案为d((n!)2)

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 1001001
#define MOD 1000000007
using namespace std;
int n;
long long ans=1;
int prime[M],tot;
bool not_prime[M];
void Linear_Shaker()
{
    int i,j;
    for(i=2;i<=n;i++)
    {
        if(!not_prime[i])
            prime[++tot]=i;
        for(j=1;prime[j]*i<=n;j++)
        {
            not_prime[prime[j]*i]=true;
            if(i%prime[j]==0)
                break;
        }
    }
}
int main()
{
    int i;
    cin>>n;
    Linear_Shaker();
    for(i=1;i<=tot;i++)
    {
        int temp=n;
        long long cnt=0;
        while(temp)
            cnt+=temp/prime[i],temp/=prime[i];
        cnt=(cnt<<1|1)%MOD;
        (ans*=cnt)%=MOD;
    }
    cout<<ans<<endl;
}
时间: 2024-08-30 05:18:15

BZOJ 2721 Violet 5 樱花 数论的相关文章

【bzoj2721】[Violet 5]樱花 数论

题目描述 输入 输出 样例输入 2 样例输出 3 题解 数论 设1/x+1/y=1/m,那么xm+ym=xy,所以xy-xm-ym+m^2=m^2,所以(x-m)(y-m)=m^2. 所以解的数量就是m^2的约数个数. 所以只需要算出n!中每个素数的出现次数即可. 我们可以先快筛出1~n的素数,然后考虑每个素数出现的次数. 而p出现的次数为包含p^1的数的个数+包含p^2的数的个数+...+包含p^k的数的个数,我们可以迭代来求. 最后把它们乘2加1再乘到一起即可. #include <cstd

2721: [Violet 5]樱花|约数个数

先跪一发题目背景QAQ 显然x,y>n!,然后可以设y=n!+d 原式子可以化简成 x=n!2d+n! 那么解的个数也就是n!的因子个数,然后线性筛随便搞一搞 #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<queue> #include<vector> #include<set> #include<ma

二分+最短路判定 BZOJ 2709: [Violet 1]迷宫花园

BZOJ 2709: [Violet 1]迷宫花园 Sample Input 5 10.28 9 9 ######### # # # # # # # #S# # ##### # # ## # # # ### ### ##E # ######### 4.67 9 9 ######### # ## ## ### #S# # # # E ## # # ##### # ## ### # ##### # # # # ######### 39.06 9 9 ######### # # # # # # # #

BZOJ 2721 樱花

问题转化为求(n!)^2有多少个约数. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 1005000 #define mod 1000000007 using namespace std; long long n,cnt[maxn],a[maxn]; void es_shaker() { for (long long i=1;i&l

【BZOJ】【2219】数论之神

中国剩余定理+原根+扩展欧几里得 题解:http://blog.csdn.net/regina8023/article/details/44863519 新技能get√: 1 LL Get_yuangen(LL p,LL phi){ 2 int c=0; 3 for(int i=2;i*i<=phi;i++) 4 if (phi%i==0) 5 f[++c]=i,f[++c]=phi/i; 6 for(int g=2;;g++){ 7 int j; 8 for(j=1;j<=c;j++) if

BZOJ 2725: [Violet 6]故乡的梦 最短路+线段树

2725: [Violet 6]故乡的梦 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 678  Solved: 204[Submit][Status][Discuss] Description Input Output Sample Input 6 7 1 2 1 2 3 1 3 4 2 4 5 1 5 6 1 1 3 3 4 6 3 1 6 4 1 2 1 3 4 3 6 5 Sample Output 7 6 Infinity 7 HINT

BZOJ 2724: [Violet 6]蒲公英

2724: [Violet 6]蒲公英 Time Limit: 40 Sec  Memory Limit: 512 MBSubmit: 1633  Solved: 563[Submit][Status][Discuss] Description Input 修正一下 l = (l_0 + x - 1) mod n + 1, r = (r_0 + x - 1) mod n + 1 Output Sample Input 6 3 1 2 3 2 1 2 1 5 3 6 1 5 Sample Outp

BZOJ 2718: [Violet 4]毕业旅行( 最长反链 )

一不小心速度就成了#1.... 这道题显然是求最长反链, 最长反链=最小链覆盖.最小链覆盖就是先做一次floyd传递闭包, 再求最小路径覆盖. 最小路径覆盖=N - 二分图最大匹配. 所以把所有点拆成x,y两个, 然后存在edge(u,v)就连ux->vy. 然后跑匈牙利即可. ------------------------------------------------------------------ #include<bits/stdc++.h> using namespace

[BZOJ 2724] [Violet 6] 蒲公英 【分块】

题目链接:BZOJ - 2724 题目分析 这道题和 BZOJ-2821 作诗 那道题几乎是一样的,就是直接分块,每块大小 sqrt(n) ,然后将数字按照数值为第一关键字,位置为第二关键字排序,方便之后二分查找某个值在某个区间内出现的次数. 预处理出 f[i][j] 即从第 i 块到第 j 块的答案. 对于每个询问,中间的整块直接用预处理出的,两端的 sqrtn 级别的数暴力做,用二分查找它们出现的次数. 每次询问的复杂度是 sqrtn * logn . 注意:写代码的时候又出现了给 sort