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\n",yy[i]);
}
ans=ans*(2*now+1);
printf("%lld\n",ans+1>>1);
}

BZOJ_4459_[Jsoi2013]丢番图_数学+分解质因数的更多相关文章

  1. bzoj 4459: [Jsoi2013]丢番图 -- 数学

    4459: [Jsoi2013]丢番图 Time Limit: 10 Sec  Memory Limit: 64 MB Description 丢番图是亚历山大时期埃及著名的数学家.他是最早研究整数系 ...

  2. bzoj4459[Jsoi2013]丢番图

    bzoj4459[Jsoi2013]丢番图 题意: 丢番图方程:1/x+1/y=1/n(x,y,n∈N+) ,给定n,求出关于n的丢番图方程有多少组解.n≤10^14. 题解: 通分得yn+xn=xy ...

  3. 【bzoj4459】[Jsoi2013]丢番图 分解质因数

    题目描述 丢番图是亚历山大时期埃及著名的数学家.他是最早研究整数系数不定方程的数学家之一.为了纪念他,这些方程一般被称作丢番图方程.最著名的丢番图方程之一是x^N+y^n=z^N.费马提出,对于N&g ...

  4. BZOJ 4459: [Jsoi2013]丢番图 数学推导

    之前绝对做过几乎一模一样的题,现在做竟然忘了. code: #include <bits/stdc++.h> #define ll long long #define setIO(s) f ...

  5. [luogu5253]丢番图【数学】

    传送门 [传送门] 题目大意 求\(\frac{1}{x}+\frac{1}{y}=\frac{1}{n}\)有多少组不同的解. 分析 将式子转化成\((n-x)(n-y)=n^2\)的形式. 那么很 ...

  6. 【bzoj4459】JSOI2013丢番图

    某JSOI夏令营出题人啊,naive! 你还是得学习个,搬这种原题不得被我一眼看穿? 求个n^2的约数除以二,向上取整. #include<bits/stdc++.h> using nam ...

  7. Project Euler 110:Diophantine reciprocals II 丢番图倒数II

    Diophantine reciprocals II In the following equation x, y, and n are positive integers. For n = 4 th ...

  8. Project Euler 108:Diophantine reciprocals I 丢番图倒数I

    Diophantine reciprocals I In the following equation x, y, and n are positive integers. For n = 4 the ...

  9. BZOJ_2467_[中山市选2010]生成树_数学

    BZOJ_2467_[中山市选2010]生成树_数学 [Submit][Status][Discuss] Description 有一种图形叫做五角形圈.一个五角形圈的中心有1个由n个顶点和n条边组成 ...

随机推荐

  1. Cow Exhibition (01背包)

    "Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - Cows with G ...

  2. left join 与left outer join的区别

    joinn 语句有三种:inner join, left outer join 和 right outer join都可以简写,分别为join,left join,right join.

  3. poj3207:Ikki's Story IV-Panda's Trick【2-sat tarjan】

    题目大意:圆盘上顺次安放0, 1, 2, …, n – 1的点,每次给出两个点需要连边,可以选择在圆盘的正面连边或在圆盘的反面连边,问是否存在一种方案使得所有连线不相交? 思路:本问题可以等价成:圆盘 ...

  4. hdu4352 XHXJ's LIS(数位DP + LIS + 状态压缩)

    #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefully reading the entire ...

  5. ThinkPHP5 的入门学习

    与Tp3.2相比,有一下的不同: (1)目录名称的改变: tp3.2的目录命名首字母皆为大写,例如:Application.Public.Controller.Model.View.ThinkPHP. ...

  6. The Bottom of a Graph

                                    poj——The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K ...

  7. [Bzoj4182]Shopping(点分治)(树上背包)(单调队列优化多重背包)

    4182: Shopping Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 374  Solved: 130[Submit][Status][Disc ...

  8. web应用启动的时候SpringMVC容器加载过程

    <!-- 配置DispatcherServlet --> <servlet> <servlet-name>springmvc</servlet-name> ...

  9. Spring实战Day2

    创建对象之后如何体现对象之间的依赖? Spring容器负责创建Bean和依赖注入,那么Spring是怎么将Bean装配在一起的呢? Spring提供了三种方式装配机制 1.隐式的bean发现机制和自动 ...

  10. Java中long(Long)与int(Integer)之间的转换(转)

    一.将long型转化为int型,这里的long型是基础类型: long a = 10; int b = (int)a; 二.将Long型转换为int型,这里的Long型是包装类型: Long a = ...