思路:

因为x,y必须要大与n,那么将y设为(n+k);那么根据等式可求的x=(n2)/k+n;因为y为整数所以k要整除n*n;

那么符合上面等式的x,y的个数就变为求能被n*n整除的数k的个数,且k>=n;

那么k就在n到n*n之间,不过这样不则么好求。

因为x,y具有对称性,从y=(n+k)和x=(n2)/k+n;也可以看出(n*n/k,和k等价因为k*(n*n/k)=n*n);

由于任何数都可以拆成素数的乘积,形式为a1^x1*a2^x2*a3*^x3......;

那么因数的个数为(1+x1)*(1+x2)*(1+x3)......,要求的是n*n,,n和n*n的素因子种类是相同的,所以n*n的因数个数为(1+2*x1)*(1+2*x2)*(1+2*x3).....;

那么求n*n的因数个数,只要求n的因数个数。

求因数个数就要先求素因数,求n的素因数打表就行了,素数打表只要打到1e5就行了,

因为在sqrt(n)之后如果要有n的素因数的话只会有一个因为如果有两个大与sqrt(n)的素因数那么设一个x1,另一个x2,就有x1*x2>n,

所以不可能有两个以上的且大于sqrt(n)的素因数。那么如果前面的素数中找完后,n还>1,那么此时n就是那个素因数,那么这对应素数的重复个数就为1。

关于因数个数(1+x1)*(1+x2)*(1+x3)......中1+xk表示的是第k个素因数能选的不同数量,那么乘起来就是不同的因数个数(1+x1)*(1+x2)*(1+x3)......了;

 1 #include<stdio.h>
2 #include<algorithm>
3 #include<stdlib.h>
4 #include<string.h>
5 #include<iostream>
6 #include<math.h>
7 const int Y=1e5+3;
8 const int uu=1e5;
9 const int Z=1e4;
10 bool flag[Y];
11 int prime[Z];
12 using namespace std;
13 int main(void)
14 {
15 int n,i,j,k,p,q;
16 memset(flag,0,sizeof(flag));
17 flag[0]=true;
18 flag[1]=true;
19 for(i=2; i<1000; i++)
20 {
21 if(!flag[i])
22 {
23 for(j=i; j*i<=uu; j++)
24 {
25 flag[i*j]=true;
26 }
27 }
28
29 }
30 int cnt=0;
31 for(i=2; i<uu; i++)
32 {
33 if(flag[i]==false)
34 {
35 prime[cnt++]=i;
36 }
37 }//素数打表存0到1e5间的素数。
38 cin>>k;
39 {
40 for(q=1; q<=k; q++)
41 {
42 cin>>p;
43 int sum=1;
44 for(i=0; i<cnt&&p>1; i++)
45 {
46 for(j=0; p%prime[i]==0; j++)
47 {
48 p=p/prime[i];
49 }//每个素因子的个数
50 sum*=(1+2*j);
51 }
52 if(p>1)//特判,在1e5之后的p的素因子(最多一个)。
53 {
54 sum*=3;
55 }
56 cout<<"Scenario #"<<q<<":"<<endl;
57 cout<<(sum+1)/2<<endl;//因为在x,y相等时只算了一次,所以要加1
58 printf("\n");
59 }
60 }
61 return 0;
62
63 }

hdu-1299 Diophantus of Alexandria(分解素因子)的更多相关文章

  1. hdu 1299 Diophantus of Alexandria(数学题)

    题目链接:hdu 1299 Diophantus of Alexandria 题意: 给你一个n,让你找1/x+1/y=1/n的方案数. 题解: 对于这种数学题,一般都变变形,找找规律,通过打表我们可 ...

  2. hdu 1299 Diophantus of Alexandria (数论)

    Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  3. 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+ ...

  4. hdoj 1299 Diophantus of Alexandria

    hdoj 1299 Diophantus of Alexandria 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1299 题意:求 1/x + 1/y ...

  5. hdu Diophantus of Alexandria(素数的筛选+分解)

    Description Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of ...

  6. 数学--数论--HDU 1299 +POJ 2917 Diophantus of Alexandria (因子个数函数+公式推导)

    Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first ma ...

  7. HDU 1299 基础数论 分解

    给一个数n问有多少种x,y的组合使$\frac{1}{x}+\frac{1}{y}=\frac{1}{n},x<=y$满足,设y = k + n,代入得到$x = \frac{n^2}{k} + ...

  8. Hdu 1299

    Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  9. Diophantus of Alexandria[HDU1299]

    Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...

随机推荐

  1. leetcode刷题之数组NO.4

    1.题目 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序. 示例: 输入: [0,1,0,3,12] 输出: [1,3,12,0,0] 说明: 必须在原数 ...

  2. 关于写SpringBoot+Mybatisplus+Shiro项目的经验分享四:部署到阿里云

    框架: SpringBoot+Mybatisplus+Shiro 简单介绍:关于写SpringBoot+Mybatisplus+Shiro项目的经验分享一:简单介绍 阿里云开放必要端口,mysql与t ...

  3. Java日期格式转换不用发愁

    前言 Java 中日期.时间相关的类相当的多,并且分不同的版本提供了不同的实现,包括 Date . Calendar . LocalDateTime . ZoneDateTime . OffsetDa ...

  4. A Child's History of England.25

    It was a September morning, and the sun was rising, when the King was awakened from slumber by the s ...

  5. 外网无法访问hdfs文件系统

    由于本地测试和服务器不在一个局域网,安装的hadoop配置文件是以内网ip作为机器间通信的ip. 在这种情况下,我们能够访问到namenode机器, namenode会给我们数据所在机器的ip地址供我 ...

  6. HTML5 之 FileReader 的使用 (二) (网页上图片拖拽并且预显示可在这里学到) [转载]

    转载至 : http://www.360doc.com/content/14/0214/18/1457948_352511645.shtml FileReader 资料(英文): https://de ...

  7. C++之无子数

    题目如下: 1 #include <iostream> 2 3 using namespace std; 4 5 6 bool isThisNumhaveChild(int num); 7 ...

  8. Oracle中建表及表操作

    一.创建表 Oracle中的建表语句:create table 表名( 字段名1 数据类型 列属性,字段名2 数据类型 列属性,...... ) 如:创建表OA_DM.DM_GY_USER https ...

  9. 图书管理系统总结——JAVA Swing控件简介

    断断续续学习JAVA语言,写了一个多月数据库大作业,终于在五一过后写完了.由于第一次使用JAVA和数据库,遇到了许多问题,记录下来,以备以后查看. 我使用的JAVA SE,说实话,在开发后期,觉得JA ...

  10. 关系型数据库和非关系型数据库区别、oracle与mysql的区别

    一.关系型数据库 关系型数据库,是指采用了关系模型来组织数据的数据库.    关系模型是在1970年由IBM的研究员E.F.Codd博士首先提出的,在之后的几十年中,关系模型的概念得到了充分的发展并逐 ...