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 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
随机推荐
- 01网页<head></head>常用标记及属性
网页<head></head>常用标记及属性 <!DOCTYPE html> <html> <head> <!--网页标题--> ...
- Python学会之后,一般能拿到多少工资?
Python在约40年前出现以来,已经有数以千计基于这项技术的网站和软件项目,Python因其独有的特点从众多开发语言中脱颖而出,深受世界各地的开发者喜爱. 随着Python的技术的流行,Python ...
- flipt 一个基于golang 的特性工具开发类库
以前介绍过一个Flagr 的基于golang 的特性功能开发类库(技术雷达推荐),今天看到一个类似也很不错的方案flipt 参考架构 包含的特性 快速,使用golang 编写,同时进行了性能优化 运行 ...
- JS设计模式—节流模式的实际应用
在实际工作中,我们会经常遇到这样的业务场景,比如点击按钮提交表单,点击一次发一次请求,如果快速点击多次会发送多次请求,这样发送了多次请求是我们不愿意看到的.又比如输入框我们输入内容会调搜索的接口,那么 ...
- BZOJ 4819 Luogu P3705 [SDOI2017]新生舞会 (最大费用最大流、二分、分数规划)
现在怎么做的题都这么水了.. 题目链接: (bzoj) https://www.lydsy.com/JudgeOnline/problem.php?id=4819 (luogu) https://ww ...
- 【04】JSONP 教程
JSONP 教程 Jsonp(JSON with Padding) 是 json 的一种"使用模式",可以让网页从别的域名(网站)那获取资料,即跨域读取数据. 为什么我们从不同的域 ...
- 【Codeforces 466B】Wonder Room
[链接] 我是链接,点我呀:) [题意] 让你把长为a,宽为b的房间扩大(长和宽都能扩大). 使得它的面积达到6*n 问你最小的能满足要求的面积是多少 输出对应的a和b [题解] 假设a< b ...
- Docker学习总结(17)——学会使用Dockerfile
Docker.Dockerfile.Docker镜像.容器这些都是什么鸟? 老生常谈,再再再--普及一下: Docker: 最早是dotCloud公司出品的一套容器管理工具,但后来Docker慢慢火起 ...
- 常见的HTTP状态码(HTTP Status Code)
HTTP状态码 当使用浏览器访问一个网页时,浏览器会向网页所在服务器发出请求.当浏览器接收并显示网页前,此网页所在的服务器会返回一个包含HTTP状态码的信息头(server header)用以响应浏览 ...
- ZooKeeper实现配置中心的实例(原生API实现)(转)
说明:要实现配置中心的例子,可以选择的SDK有很多,原生自带的SDK也是不错的选择.比如使用I0Itec,Spring Boot集成等. 大型应用通常会按业务拆分成一个个业务子系统,这些大大小小的子应 ...