hdu Diophantus of Alexandria(素数的筛选+分解)
Description
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?
Input
Output
Sample Input
4
1260
Sample Output
3
Scenario #2:
113
#include <string.h>
#include <stdio.h>
#define M 40000
int prime[];
void dabiao()//筛选素数
{
int i,j;
memset(prime,,sizeof(prime));
for(i=; i<=M; i++)
{
if(prime[i]==)
{
for(j=i+i; j<=M; j+=i)
{
prime[j]=;
}
}
}
}
int fenjie(int n)//素数因子分解
{
int i,k,sum=;
for(i=; i<=M; i++)
{
if(n==)
break;
if(prime[i]==)
{
k=;
while(n%i==)
{
k++;
n=n/i;
}
sum=sum*(*k+);
}
}
if(n>)
sum=sum*;
return sum;
}
int main()
{ dabiao();
int n,i,j,t;
scanf("%d",&t);
int p=;
while(t--)
{
scanf("%d",&n);
printf("Scenario #%d:\n",p);
printf("%d\n\n",(fenjie(n)+)/);
p++;
}
return ;
}
hdu Diophantus of Alexandria(素数的筛选+分解)的更多相关文章
- HDOJ/HDU 2710 Max Factor(素数快速筛选~)
Problem Description To improve the organization of his farm, Farmer John labels each of his N (1 < ...
- 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(数学题)
题目链接:hdu 1299 Diophantus of Alexandria 题意: 给你一个n,让你找1/x+1/y=1/n的方案数. 题解: 对于这种数学题,一般都变变形,找找规律,通过打表我们可 ...
- 数学--数论--HDU 1299 +POJ 2917 Diophantus of Alexandria (因子个数函数+公式推导)
Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first ma ...
- hdoj 1299 Diophantus of Alexandria
hdoj 1299 Diophantus of Alexandria 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1299 题意:求 1/x + 1/y ...
- HDU 2098 分拆素数和(素数)
HDU 2098 分拆素数和(素数) http://acm.hdu.edu.cn/showproblem.php?pid=2098 题意: 给你一个偶数,问你这个偶数有多少种方式能由两个不同的素数构成 ...
- HDU 1299Diophantus of Alexandria
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 2098 分拆素数和
HDU 2098 分拆素数和 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768K (Java/Others) [题目描述 ...
随机推荐
- Source Insight 3.X 插件支持utf8,完美解决中国乱码,连接到美丽的轮廓
上次SI多标签插件之后,由于公司内部编码改为utf8编码,因此特意做了这个Source Insight 3.X utf8插件. 下载地址:http://pan.baidu.com/s/1mgyZous ...
- 《图书管理系统——java》
/* (程序头部凝视開始) * 程序的版权和版本号声明部分 * Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved. * 文件名: < ...
- c# socket udp广播
一.广播消息 由于Tcp是有连接的,所以不能用来发送广播消息.发送广播消息,必须用到Udp,Udp可以不用建立连接而发送消息.广播消息的目的IP地址是一种特殊IP地址,称为广播地址.广播地址由IP地址 ...
- 交换A与B值的四种方法
在网上看到了这样一道面试题,"int A=5,int B=2,怎样交换A与B的值",或许这是一道简单到不能再简单的题,但能作为一道面试题,肯定有其独特之处 大多数人会通过定义第三个 ...
- 信息二战炸弹:中国到美国咨询公司Say no
疯抢/文 在禁止Windows8操作系统參与政府採购,以及在中国销售的全部外国IT产品和服务都须通过新的安全审查之后,英国<金融时报>今天报料中国已禁止国企使用美国咨询公司服务. 这则消息 ...
- 【java基础】==与equals()方法比较
1.八种基本类型 只有"=="方法进行判断是否相等,比较的是基本数据类型的值,没有equals()方法 2.Java类库中的类 "=="比较的是对象的句柄,即内 ...
- 第三篇——第二部分——第四文 配置SQL Server镜像——非域环境
原文:第三篇--第二部分--第四文 配置SQL Server镜像--非域环境 本文为非域环境搭建镜像演示,对于域环境搭建,可参照上文:http://blog.csdn.net/dba_huangzj/ ...
- Cocos2d-x 3.0final 终结者系列教程04-引擎架构分析
从前,有一个跟我来Android学生,总是问我: 沉老师,为什么Android的形式被称为Activity,为什么要onCreate方法写setContentView(R.layout.main)? ...
- MFC 盾webBrowser打开弹出的页面
void CansDlg::NewWindow3Explorer1(LPDISPATCH* ppDisp, BOOL* Cancel, unsigned long dwFlags, LPCTSTR b ...
- linux下getsockopt和setsockopt具体解释及測试
linux下getsockopt和setsockopt具体解释及測试 NAME 名字 getsockopt, setsockopt - get and set options on sockets 获 ...