思路:

因为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. Docker镜像相关操作

    批量导入镜像 ll *.tgz|awk '{print $NF}'|sed -r 's#(.*)#docker load -i \1#' |bash 批量打tag docker images | se ...

  2. UE4类型数据自动注册

    Version:4.26.2 UE4 C++工程名:MyProject 在<宏GENERATED_BODY做了什么?>中,简单分析了GENERATED_BODY宏给一个简单的.继承自UOb ...

  3. 线性表A,B顺序存储合并

    线性表A,B顺序存储合并 有两张非递增有序的线性表A,B,采用顺序存储结构,两张表合并用c表存,要求C为非递减有序的,然后删除C表中值相同的多余元素.元素类型为整型 输入格式: 第一行输入输入表A的各 ...

  4. 从分布式锁角度理解Java的synchronized关键字

    分布式锁 分布式锁就以zookeeper为例,zookeeper是一个分布式系统的协调器,我们将其理解为一个文件系统,可以在zookeeper服务器中创建或删除文件夹或文件.设D为一个数据系统,不具备 ...

  5. Kafka 架构深入

    Kafka 工作流程及文件存储机制

  6. 容器之分类与各种测试(三)——forward_list的用法

    forward_list是C++11规定的新标准单项链表,slist是g++以前的规定的单项链表 例程 #include<stdexcept> #include<string> ...

  7. springboot热部署与监控

    一.热部署 添加依赖+Ctrl+F9 <dependency> <groupId>org.springframework.boot</groupId> <ar ...

  8. Function overloading and return type

    In C++ and Java, functions can not be overloaded if they differ only in the return type. For example ...

  9. 【编程思想】【设计模式】【创建模式creational】Borg/Monostate

    Python版 https://github.com/faif/python-patterns/blob/master/creational/borg.py #!/usr/bin/env python ...

  10. List如何一边遍历,一边删除?

    1.新手常犯的错误 可能很多新手(包括当年的我,哈哈)第一时间想到的写法是下面这样的: public static void main(String[] args) { List<String& ...