hdu-1299 Diophantus of Alexandria(分解素因子)
思路:
因为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(分解素因子)的更多相关文章
- hdu 1299 Diophantus of Alexandria(数学题)
题目链接:hdu 1299 Diophantus of Alexandria 题意: 给你一个n,让你找1/x+1/y=1/n的方案数. 题解: 对于这种数学题,一般都变变形,找找规律,通过打表我们可 ...
- 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 Diophantus of Alexandria(素数的筛选+分解)
Description Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of ...
- 数学--数论--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 1299 基础数论 分解
给一个数n问有多少种x,y的组合使$\frac{1}{x}+\frac{1}{y}=\frac{1}{n},x<=y$满足,设y = k + n,代入得到$x = \frac{n^2}{k} + ...
- 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 ...
随机推荐
- Demo01无重复数字
package 习题集2;//有1,2,3,4四个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?public class Demo1 { public static void main(S ...
- js获取中国省市区,省市筛选、省市、省市筛选联动。【C#】【js】
<style type="text/css"> .labelhide { -webkit-box-shadow: 0px 1px 0px 0px #f3f3f3 !im ...
- adhere, adjust, adjacent
adhere to stick,不是to here. 在古英语里,stick是twig(细树枝).fasten(想必是用twig来固定).后引申为粘住.stick还有stab, pierce的意思,想 ...
- 淘宝、网易移动端 px 转换 rem 原理,Vue-cli 实现 px 转换 rem
在过去的一段时间里面一直在使用Vue配合 lib-flexible和px2rem-loader配合做移动端的网页适配.秉着求知的思想,今天决定对他的原理进行分析.目前网上比较主流使用的就是淘宝方 ...
- Excel 数据验证:分类选择及输入限制
几个简单设置让你的数据不再出错 如何快速选择某一大类中的细分小类 多级菜单 注意:引用可以创建二级目录,但是引用前应先用公式定义名称,然后引用,引用只能在本sheet操作.
- python 从ubantu环境迁移到windows环境
下载安装Anaconda3 Anaconda3-2021.05-Windows-x86_64.exe 默认安装目录 C:\ProgramData\Anaconda3 可以启动Anaconda查看不同的 ...
- 小程序中使用less(最优方式)
写惯了less/sass,但是现在开发小程序缺还是css,很不习惯. 在网上搜的教程,要么是gulp,要么就是vscode的Easy-less的插件. 传统方式 我们来对比,这两种方式的优劣. Gul ...
- SSM框架整合后使用pagehelper实现分页功能
一.导入pagehelper-5.1.10.jar和jsqlparser-3.1.jar两个jar包 二.配置pagehelper 2.1 在mybatis配置文件中配置 <plugins> ...
- 转: 再谈select, iocp, epoll,kqueue及各种I/O复用机制
首先,介绍几种常见的I/O模型及其区别,如下: blocking I/O nonblocking I/O I/O multiplexing (select and poll) signal drive ...
- MySQL慢日志优化
慢日志的性能问题 造成 I/O 和 CPU 资源消耗:慢日志通常会扫描大量非目的的数据,自然就会造成 I/O 和 CPU 的资源消耗,影响到其他业务的正常使用,有可能因为单个慢 SQL 就能拖慢整个数 ...