HDU 1299Diophantus of Alexandria
Diophantus of Alexandria
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3210 Accepted Submission(s): 1269
Consider the following diophantine equation:
1 / x + 1 / y = 1 / n where x, y, n ∈ N+ (1)
Diophantus is interested in the following question: for a given n, how many distinct solutions (i. e., solutions satisfying x ≤ y) does equation (1) have? For example, for n = 4, there are exactly three distinct solutions:
1 / 5 + 1 / 20 = 1 / 4
1 / 6 + 1 / 12 = 1 / 4
1 / 8 + 1 / 8 = 1 / 4
Clearly, enumerating these solutions can become tedious for bigger values of n. Can you help Diophantus compute the number of distinct solutions for big values of n quickly?
4
1260
3
113
以前留下来的题目,今天才补。
题目大意就是给定n求有多少种x,y的组合 使得1/x+1/y=1/n;
因为x,y都大于n,这样我们可以设y=x+k 那么上边的等式可以化成x=n*n/k+n;
问题变成求有多少种x了,x是整数,多疑k要是n*n的因子才行.
由于任意一个数都可以表示成 n=p1^r1*p2^r2*p3^r3.....pi^ri 这种形式(其中pi是素数),那么因子的数量就是(r1+1)*(r2+1)*(r3+1)....*(ri+1).(因为每种pi可以选择ri个嘛也可以不选)
那么 n*n的因子数呢? 同理可得n*n的因子数为(2*r1+1)*(2*r2+1)*(2*r3+1)....*(2*ri+1)个
/* ***********************************************
Author :guanjun
Created Time :2016/10/9 18:38:22
File Name :hdu1299.cpp
************************************************ */
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
int n;
int prime[];
int vis[];
int num;
void init(){
num=;
memset(vis,,sizeof vis);
int x=sqrt()+;
for(int i=;i<=x;i++){
if(!vis[i]){
prime[++num]=i;
for(int j=i;j<=x;j+=i)vis[j]=;
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
init();
int t;
cin>>t;
for(int k=;k<=t;k++){
scanf("%d",&n);
ll ans=;
int p,cnt;
for(int i=;i<=num;i++){
p=prime[i];
cnt=;
if(p*p>n)break;
while(n%p==){
cnt++;
n/=p;
}
ans*=(*cnt+);
}
if(n>)ans*=;
printf("Scenario #%d:\n",k);
printf("%lld\n\n",(ans+)/);
}
return ;
}
真是醉了,筛素数的时候,x=100000和10000是 num会出现诡异的变化....科学事故啊
HDU 1299Diophantus of Alexandria的更多相关文章
- hdu Diophantus of Alexandria(素数的筛选+分解)
Description Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of ...
- hdu 1299 Diophantus of Alexandria(数学题)
题目链接:hdu 1299 Diophantus of Alexandria 题意: 给你一个n,让你找1/x+1/y=1/n的方案数. 题解: 对于这种数学题,一般都变变形,找找规律,通过打表我们可 ...
- hdu 1299 Diophantus of Alexandria (数论)
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 数学--数论--HDU 1299 +POJ 2917 Diophantus of Alexandria (因子个数函数+公式推导)
Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first ma ...
- hdu 1299 Diophantus of Alexandria
1/x + 1/y = 1/n 1<=n<=10^9给你 n 求符合要求的x,y有多少对 x<=y// 首先 x>n 那么设 x=n+m 那么 1/y= 1/n - 1/(n+ ...
- hdoj 1299 Diophantus of Alexandria
hdoj 1299 Diophantus of Alexandria 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1299 题意:求 1/x + 1/y ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
随机推荐
- php file_get_contents函数分段读取大记事本或其它文本文件
当我们遇到文本文件体积很大时,比如超过几十M甚至几百M几G的大文件,用记事本或者其它编辑器打开往往不能成功,因为他们都需要把文件内容全部放到内存里面,这时就会发生内存溢出而打开错误,遇到这种情况我们可 ...
- 【Hadoop】三、HDFS命令行接口
通过前面对HDFS基本概念.高可用性.数据读写流程的介绍,我们对HDFS已经有了大致的了解.这里我们还需要明确一点:Hadoop作为一个完整的分布式系统,它有一个抽象的文件系统的概念,而我们介绍的 ...
- java命令行版的ATM
import java.util.*;public class Jatm{ static String user = "123"; static String password = ...
- Bullet:ORACLE Using SQL Plan Management(一)
SQL Plan Management如何工作? 当一个SQL硬解析时,基于成本的优化器CBO会生成多个执行计划,并从这些执行计划中选择一个优化器认为最低成本的执行计划. 如果SQL plan bas ...
- Xmind的使用
Xmind是用来学习整理思维的工具
- 洛谷——P2801 教主的魔法(线段树or分块)
P2801 教主的魔法 (1) 若第一个字母为“M”,则紧接着有三个数字L.R.W.表示对闭区间 [L, R] 内所有英雄的身高加上W. (2) 若第一个字母为“A”,则紧接着有三个数字L.R.C.询 ...
- KMP瞎扯一下
什么是KMP KMP俗称看毛片算法,是高效寻找匹配字串的一个算法 百度百科 KMP算法是一种改进的字符串匹配算法,由D.E.Knuth,J.H.Morris和V.R.Pratt同时发现,因此人们称它为 ...
- docker 部署spring.boot项目【一】(引用外部配置文件)
上一篇随笔,nginx是启动运行在容器内,spring.boot的web项目是运行在宿主内,这一篇的目的,是把web项目也制作成镜像,然后在容器里启动. 文件目录结构如下: 主要文件结构说明:(1)b ...
- Linux学习笔记(六) 进程管理
1.进程基础 当输入一个命令时,shell 会同时启动一个进程,这种任务与进程分离的方式是 Linux 系统上重要的概念 每个执行的任务都称为进程,在每个进程启动时,系统都会给它指定一个唯一的 ID, ...
- DemoKit编译过程错误
1.编译出错: 2.原因(将代码注释):