zoukankan      html  css  js  c++  java
  • BZOJ_4459_[Jsoi2013]丢番图_数学+分解质因数

    BZOJ_4459_[Jsoi2013]丢番图_数学+分解质因数

    Description

    丢番图是亚历山大时期埃及著名的数学家。他是最早研究整数系数不定方程的数学家之一。
    为了纪念他,这些方程一般被称作丢番图方程。最著名的丢番图方程之一是x^N+y^n=z^N。费马
    提出,对于N>2,x,y,z没有正整数解。这被称为“费马大定理”,它的证明直到最近才被安德
    鲁·怀尔斯(AndrewWiles)证明。
    考虑如下的丢番图方程:
    1/x+1/y=1/n(x,y,n属于N+)                      (1)
    小G对下面这个问题十分感兴趣:对于一个给定的正整数n,有多少种本质不同的解满足方
    程(1)?例如n=4,有三种本质不同(x≤y)的解:
    1/5+1/20=1/4
    1/6+1/12=1/4
    1/8+1/8=1/4
    显然,对于更大的n,没有意义去列举所有本质不同的解。你能否帮助小G快速地求出对于
    给定n,满足方程(1)的本质不同的解的个数?

    Input

    一行,仅一个整数n(1<=N<=10^14)

    Output

    一行,输出对于给定整数n,满足方程(1)的本质不同的解的个数。

    Sample Input

    4

    Sample Output

    3

    $frac{1}{x}+frac{1}{y}=frac{1}{n}$
    $xn+yn=xy$
    $(x-n)*(y-n)=n^{2}$
    于是转化为了求$n$的约数个数。
     
    代码:
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <stdlib.h>
    #include <math.h>
    using namespace std;
    typedef long long ll;
    int a[]={2,3,5,7,11,13,17,19,23};
    ll ch(ll a,ll b,ll mod) {
        ll d=(ll)floor(1.0*a/mod*b+0.5),re=a*b-d*mod; return re<0?re+mod:re;
    }
    ll random(ll l,ll r) {
        return ((rand()*(1ll<<45))+(rand()<<30)+(rand()<<15)+(rand()))%(r-l+1)+l;
    }
    ll qp(ll x,ll y,ll mod) {
        ll re=1;
        for(;y;y>>=1ll,x=ch(x,x,mod)) if(y&1) re=ch(re,x,mod); return re;
    }
    ll Abs(ll x) {return x>0?x:-x;}
    ll gcd(ll x,ll y) {return y?gcd(y,x%y):x;}
    ll yy[23333];
    bool check(ll a,ll n,ll r,ll s) {
        ll x=qp(a,r,n),y=x;
        int i;
        for(i=1;i<=s;i++,y=x) {
            x=ch(x,x,n);
            if(x==1&&y!=1&&y!=n-1) return 0;
        }
        return x==1;
    }
    bool MR(ll n) {
        if(n<=1) return 0;
        ll r=n-1,s=0;
        int i;
        for(;!(r&1);r>>=1ll,s++);
        for(i=0;i<3;i++) {
            if(a[i]==n) return 1;
            if(!check(a[i],n,r,s)) return 0;
        }
        return 1;
    }
    ll PR(ll n,ll c) {
        ll x=random(0,n-1),y=x,p;
        for(p=1;p==1;) {
            x=(ch(x,x,n)+c)%n;
            y=(ch(y,y,n)+c)%n;
            y=(ch(y,y,n)+c)%n;
            p=gcd(Abs(x-y),n);
        }
        return p;
    }
    void solve(ll n) {
        if(n<=1) return ;
        if(MR(n)) {
            yy[++yy[0]]=n; return ;
        }
        ll tmp=n;
        while(tmp==n) tmp=PR(n,random(0,n-1));
        solve(tmp); solve(n/tmp);
    }
    int main() {
        ll n;
        scanf("%lld",&n);
        while(n%2==0) {
            yy[++yy[0]]=2; n/=2;
        }
        solve(n);
        sort(yy+1,yy+yy[0]+1);
        ll lst=-1;
        int i,now=0;
        ll ans=1;
        for(i=1;i<=yy[0];i++) {
            if(lst!=yy[i]) {
                ans=ans*(2*now+1);
                now=0; lst=yy[i];
            }
            now++;
            // printf("%lld
    ",yy[i]);
        }
        ans=ans*(2*now+1);
        printf("%lld
    ",ans+1>>1);
    }
    
  • 相关阅读:
    Eclipse中常用的快捷键总结!不收藏后悔!
    MySQL基本命令整理,java数据库秘籍!
    centos 禁用ip v6
    win7 & win10 安装AD管理工具
    CentOS LVM 卷在线扩容
    Windows 与 Linux 、esxi下面查看内存容量和数量
    ESX/ESXi 主机上的每个插槽中安装了多少内存
    使用 esxcli storage vmfs unmap 命令在精简置备的 LUN 上回收 VMFS 删除的块
    vSphere 高级特性FT配置与管理
    vSphere HA 原理与配置
  • 原文地址:https://www.cnblogs.com/suika/p/9188397.html
Copyright © 2011-2022 走看看