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. Food Delivery (区间DP)

    When we are focusing on solving problems, we usually prefer to stay in front of computers rather tha ...

  2. oracle sqlplus 导出csv文件

    et colsep , set feedback off set heading off set trimout on spool D:\DBoracle\lfc.csv select '" ...

  3. Codeforces Round #277 (Div. 2 Only)

    A:SwapSort http://codeforces.com/problemset/problem/489/A 题目大意:将一个序列排序,可以交换任意两个数字,但要求交换的次数不超过n,输出任意一 ...

  4. VS Code 列编辑功能说明

    新版本v1.13.1或者附近的版本中的列编辑功能已经调整. 一.多光标插入功能 Alt+鼠标左键,添加多光标输入 二.自由多行选择 Alt键+鼠标左键拖动选择各行的部分内容 三.列选择 Shift+A ...

  5. ubuntu,CentOS永久修改主机名

    1.查看主机名 在Ubuntu系统中,快速查看主机名有多种方法: 其一,打开一个GNOME终端窗口,在命令提示符中可以看到主机名,主机名通常位于“@”符号后: 其二,在终端窗口中输入命令:hostna ...

  6. mybatis连接mysql

    配置web.xml 1. <context-param> 参考文章 <context-param>    <param-name>contextConfigLoca ...

  7. Method, apparatus and system for acquiring a global promotion facility utilizing a data-less transaction

    A data processing system includes a global promotion facility and a plurality of processors coupled ...

  8. 分享一下然让显卡满血复活的小技巧(GTX)

    分享一下然让显卡满血复活的小技巧 笔者在玩大型游戏卡顿15fps下载如下操作 GTX950玩大型游戏都不会卡帧率稳定在30fps 下载GeForce Experience下载更新最新驱动 下载如下程序 ...

  9. win10 笔记本猎豹WiFi无法打开

    网卡驱动太新了,先把网卡驱动卸载,重新安装一个就可以,用驱动精灵,17.15.0.5版本就可以

  10. c++多线程编程:常见面试题

    题目:子线程循环 10 次,接着主线程循环 100 次,接着又回到子线程循环 10 次,接着再回到主线程又循环 100 次,如此循环50次,试写出代码 子线程与主线程必有一个满足条件(flag == ...