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 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
随机推荐
- Masonry基础API
Masonry基础API mas_makeConstraints() 添加约束 mas_remakeConstraints() 移除之前的约束,重新添加新的约束 mas_updateConst ...
- HFS模板开发
痉挛模板, 节, 符号 & 变量帮助需要更多帮助 吗?看看 下面这些链接-模板是模型痉挛用于构建 HTML 页面. -它分为几个部分, 每个部分描述最终 HTML 页面的一部分. -此模板必须 ...
- c++类简介
C++类(Class)总结 一.C++类的定义 C++中使用关键字 class 来定义类, 其基本形式如下:class 类名{ public: //行为或属性 protected: // ...
- java虚拟机(四)--内存溢出、内存泄漏、SOF
学习了java运行时数据区,知道每个内存区域保存什么数据,可以参考:https://www.cnblogs.com/huigelaile/p/diamondshine.html,然后了 解内存溢出和内 ...
- 00Extensible Markup Language
Extensible Markup Language XML(Extensible Markup Language)可扩展标记语言是用来网络数据的组织结构,传输及存储.
- mysql5.7报Access denied for xxx@localhost 的解决
使用root用户登录mysql数据库若如下报错 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor ...
- Platform 获取主机系统信息
该模块用来访问平台相关属性. 常见属性和方法 1. import platform(pip install platform) 2.获取操作系统名称及版本号 def get_platform(): ...
- react入门-----(jsx语法,在react中获取真实的dom节点)
1.jsx语法 var names = ['Alice', 'Emily', 'Kate']; <!-- HTML 语言直接写在 JavaScript 语言之中,不加任何引号,这就是 JSX 的 ...
- RabbitMQ消息队列阻塞导致服务器宕机
最近工作中存储服务器由于压力太大无法及时消费消息.这个过程中,导致RabbitMQ意外挂掉,无法访问.下面是部分问题分析过程. 麒麟系统服务器分析 1.服务器异常信息: [root@localhost ...
- Oracle怎么用(常用工具)
Oracle数据库管理系统装好了!那要怎么用呢? 将介绍的工具:①Database Configuration Assistant ②SQL Plus ③SQL Developer 一.Dat ...