hdu 1299 Diophantus of Alexandria(数学题)
题目链接:hdu 1299 Diophantus of Alexandria
题意:
给你一个n,让你找1/x+1/y=1/n的方案数。
题解:
对于这种数学题,一般都变变形,找找规律,通过打表我们可以发现这个答案只与这个数的因子有关。
n=a1^p1*a2^p2*...*an^pn
ans=((1+2*p1)*(1+2*p2)*...*(1+2*pn)+1)/2
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;++i)
using namespace std; const int N=1e5+;
int primes[N],tot=;
bool vis[N];
void Euler(){
F(i,,N-){
if(!vis[i])primes[++tot]=i;
F(j,,tot){
if(i*primes[j]>N)break;
vis[i*primes[j]]=;
if(i%primes[j]==)break;
}
}
} int t,n,ans,cas; int main()
{
Euler();
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
ans=;
F(i,,tot)
{
if(primes[i]>n)break;
int cnt=;
while(n%primes[i]==)n/=primes[i],cnt++;
ans*=*cnt+;
}
if(n>)ans*=;
printf("Scenario #%d:\n%d\n\n",++cas,(ans+)/);
}
return ;
}
hdu 1299 Diophantus of Alexandria(数学题)的更多相关文章
- hdu 1299 Diophantus of Alexandria (数论)
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 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 ...
- 数学--数论--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 Diophantus of Alexandria(素数的筛选+分解)
Description Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of ...
- Hdu 1299
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- Diophantus of Alexandria[HDU1299]
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- HDU 1299 基础数论 分解
给一个数n问有多少种x,y的组合使$\frac{1}{x}+\frac{1}{y}=\frac{1}{n},x<=y$满足,设y = k + n,代入得到$x = \frac{n^2}{k} + ...
- Diophantus of Alexandria
Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first ma ...
随机推荐
- SpringMVC源码
SpringMVC源码分析系列 说到java的mvc框架,struts2和springmvc想必大家都知道,struts2的设计基本上完全脱离了Servlet容器,而springmvc是依托着Serv ...
- python chanllenge题解
网址:chanllenge 修改url最后的html的前缀为答案,就可以过关. 页面上很多只有一幅图片,实际上题目描述全在页面源码中. 然后推荐一个在线代码运行的网站 ideone 查看所有源码:ht ...
- Effective C++(14) 在资源管理类中小心copying行为
问题聚焦: 上一条款所告诉我们的智能指针,只适合与在堆中的资源,而并非所有资源都是在堆中的. 这时候,我们可能需要建立自己的资源管理类,那么建立自己的资源管理类时,需要注意什么呢?. ...
- SQLSERVER 数据库性能的的基本 MVC + EF + Bootstrap 2 权限管理
SQLSERVER 数据库性能的基本 很久没有写文章了,在系统正式上线之前,DBA一般都要测试一下服务器的性能 比如你有很多的服务器,有些做web服务器,有些做缓存服务器,有些做文件服务器,有些做数据 ...
- 生成自己的Webapi帮助文档(一)
最近Webapi接口的开发刚刚进入尾声,随之而来的是让用户知道接口的详细参数信息,看过淘宝的接口文档,但网上没找到他的实现方式 虽然新建Webapi时C#也会给你一个帮助文档的Area,但是总觉得有些 ...
- iOS基础 - 控制器
一.当两个控制器互为父子关系的时候,它们的view一般也是互为父子关系 比如想添加A控制器的view到B控制器的view上,就应该让A控制器成为B控制器的子控制器,而B控制器就称为A控制器的父控制器 ...
- c#二进制、十进制、16进制之间的转换
//十进制转二进制 Console.WriteLine(Convert.ToString(69, 2)); //十进制转八进制 Console.WriteLine(Convert.ToString(6 ...
- twisted学习笔记4 部署Twisted 应用程序
原创博文,转载请注明出处. Twisted是一个可扩展,跨平台的网络服务器和客户端引擎. Twisted Application 框架有五个主要基础部分组成:服务,应用程序,TAC文件插件和twist ...
- UML类图的常见关系1
设计模式之UML类图的常见关系(一) 本篇会讲解在UML类图中,常见几种关系: 泛化(Generalization),依赖(Dependency),关联(Association),聚合(Aggre ...
- 《C++游戏开发》笔记十三 平滑过渡的战争迷雾(一) 原理:Warcraft3地形拼接算法
本系列文章由七十一雾央编写,转载请注明出处. http://blog.csdn.net/u011371356/article/details/9611887 作者:七十一雾央 新浪微博:http:/ ...