hdu 1299 Diophantus of Alexandria(数学题)

题目链接:hdu 1299 Diophantus of Alexandria

题意:

给你一个n,让你找1/x+1/y=1/n的方案数。

题解:

对于这种数学题,一般都变变形,找找规律,通过打表我们可以发现这个答案只与这个数的因子有关。

n=a1^p1*a2^p2*...*an^pn

ans=((1+2*p1)*(1+2*p2)*...*(1+2*pn)+1)/2

 1 #include<bits/stdc++.h>
 2 #define F(i,a,b) for(int i=a;i<=b;++i)
 3 using namespace std;
 4
 5 const int N=1e5+7;
 6 int primes[N],tot=0;
 7 bool vis[N];
 8 void Euler(){
 9     F(i,2,N-7){
10         if(!vis[i])primes[++tot]=i;
11         F(j,1,tot){
12             if(i*primes[j]>N)break;
13             vis[i*primes[j]]=1;
14             if(i%primes[j]==0)break;
15         }
16     }
17 }
18
19 int t,n,ans,cas;
20
21 int main()
22 {
23     Euler();
24     scanf("%d",&t);
25     while(t--)
26     {
27         scanf("%d",&n);
28         ans=1;
29         F(i,1,tot)
30         {
31             if(primes[i]>n)break;
32             int cnt=0;
33             while(n%primes[i]==0)n/=primes[i],cnt++;
34             ans*=2*cnt+1;
35         }
36         if(n>1)ans*=3;
37         printf("Scenario #%d:\n%d\n\n",++cas,(ans+1)/2);
38     }
39     return 0;
40 }

时间: 2024-10-10 20:40:48

hdu 1299 Diophantus of Alexandria(数学题)的相关文章

hdu 1299 Diophantus of Alexandria (数论)

Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2269    Accepted Submission(s): 851 Problem Description Diophantus of Alexandria was an egypt mathematician living in Ale

hdu 1299 Diophantus of Alexandria

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1299 题目大意:就是给你一个n,求1/x+//y=1/n正整数解的个数. 思路:首先我们可以在两边同时乘以xyn得yn+xn=xy,然后因式分解的(x-n)*(y-n)=n*n.这题要求解的个数,就变成了求n*n的因子数,网上很多人都是令y=n+k,然后的x=(n*n)/k+n,这儿也是求n*n的因子数. 通过数论的中的学习我们知道任意一个数n都可以由素数表示出来,即: n=p1^e1*p2^e2*

hdu 4970 Killing Monsters(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4970 Problem Description Kingdom Rush is a popular TD game, in which you should build some towers to protect your kingdom from monsters. And now another wave of monsters is coming and you need again to k

HDU 2529 Shot (物理数学题)

题目 解题过程: //物理数学题 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int main() { double h,l,v,ans; while(scanf("%lf%lf%lf",&h,&l,&v)!=EOF) { if(h==0&&l==0&&v==0)break; ans

hdu 1299

这个方法太厉害了 别人的记录一下 #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<bitset> #include<iomanip> using namespace std; #define MAX_PRIME 31700 #define PRIME_NUM 3500 int

hdu 1299 数论 分解素因子

题意:求1.1/x+1/y=1/z 给定z 求x,y的个数zsd:1: 要知道这个素数的因子的范围 范围为2--sqrt(n);2: 带入方程得:x = n * n / k + n ; 现在就变成了求x的值.又因为n一定大于k,所以转换成求n * n的分解数: 因为n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en sum ( n)= ( 1 + e1 ) * ( 1 +e2 ) * .........* ( 1 +en ); sum (n * n) = ( 1

hdu 4937 Lucky Number(数学题 进制转换)2014多校训练第7场

Lucky Number                                                                          Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description "Ladies and Gentlemen, It's show time! " "A thie

HDU 1018 Big Number (数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018 解题报告:输入一个n,求n!有多少位. 首先任意一个数 x 的位数 = (int)log10(x) + 1; 所以n!的位数 = (int)log10(1*2*3*.......n) + 1; = (int)(log10(1) + log10(2) + log10(3) + ........ log10(n)) + 1; 1 #include<cstdio> 2 #include<cs

HDU 3104 Combination Lock(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3104 Problem Description A combination lock consists of a circular dial, which can be turned (clockwise or counterclockwise) and is embedded into the "fixed" part of the lock. The dial has N evenly