思路:

因为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. 搭建简单的SpringCloud项目一:注册中心和公共层

    注:笔者在搭建途中其实遇见不少问题,统一放在后面的文章说明,现在的搭建是测试OK的. GitHub:https://github.com/ownzyuan/test-cloud 后续:搭建简单的Spr ...

  2. 同一局域网,远程连接别人的Mysql数据库

    数据库:MySQL 工具: Navicat, 电脑A连接电脑B的数据库, 确保两部电脑都是在同一个局域网,都是连着同一个路由器,或者连接同一个WiFi, 如果不确定是否为同一个局域网,可以打开cmd, ...

  3. Python | 迭代器与zip的一些细节

    首先抛出一个困扰本人许久的问题: nums = [1,2,3,4,5,6] numsIter = iter(nums) for _ in zip(*[numsIter]*3): print(_) pr ...

  4. 【Redis】Sentinel 哨兵模式

    Sentinel(哨兵模式) 目录 Sentinel(哨兵模式) 哨兵模式的三个定时任务 Sentinel(哨兵)与Sentinel .主服务器.从服务器之间的连接 检测下线状态 选择领头 Senti ...

  5. 修改linux系统下mysql数据库登陆密码(密码忘记)

    报错:Access denied for user 'root'@'localhost' (using password: NO) 解决方案: 1. 检查mysql服务是否启动,如果启动,关闭mysq ...

  6. treeTable实现排序

    /* * * TreeTable 0.1 - Client-side TreeTable Viewer! * @requires jQuery v1.3 * * Dual licensed under ...

  7. Dubbo服务暴露延迟

    Dubbo 2.6.5 版本以后,如果我们的服务启动过程需要warmup事件,就可以使用delay进行服务延迟暴露.只需在服务提供者的<dubbo:service/>标签中添加delay属 ...

  8. 阿里云发布CloudOps白皮书,ECS自动化运维套件新升级

    12月10 日,2021云上架构与运维峰会上,阿里云发布业界首部<云上自动化运维白皮书>(简称CloudOps白皮书),并在其中提出了CloudOps成熟度模型.同时,阿里云还宣布了ECS ...

  9. Apache Log4j 2 报高危漏洞,CODING 联手腾讯安全护卫软件安全

    导语 12 月 9 日晚间,Apache Log4j 2 发现了远程代码执行漏洞,恶意使用者可以通过该漏洞在目标服务器上执行任意代码,危害极大. 腾讯安全第一时间将该漏洞收录至腾讯安全漏洞特征库中,C ...

  10. 一行配置搞定 Spring Boot项目的 log4j2 核弹漏洞!

    相信昨天,很多小伙伴都因为Log4j2的史诗级漏洞忙翻了吧? 看到群里还有小伙伴说公司里还特别建了800+人的群在处理... 好在很快就有了缓解措施和解决方案.同时,log4j2官方也是速度影响发布了 ...