Diophantus of Alexandria

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3210    Accepted Submission(s): 1269

Problem Description
Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first mathematicians to study equations where variables were restricted to integral values. In honor of him, these equations are commonly called diophantine equations. One of the most famous diophantine equation is x^n + y^n = z^n. Fermat suggested that for n > 2, there are no solutions with positive integral values for x, y and z. A proof of this theorem (called Fermat's last theorem) was found only recently by Andrew Wiles.

Consider the following diophantine equation:

1 / x + 1 / y = 1 / n where x, y, n ∈ N+ (1)

Diophantus is interested in the following question: for a given n, how many distinct solutions (i. e., solutions satisfying x ≤ y) does equation (1) have? For example, for n = 4, there are exactly three distinct solutions:

1 / 5 + 1 / 20 = 1 / 4
1 / 6 + 1 / 12 = 1 / 4
1 / 8 + 1 / 8 = 1 / 4

Clearly, enumerating these solutions can become tedious for bigger values of n. Can you help Diophantus compute the number of distinct solutions for big values of n quickly?

 
Input
The first line contains the number of scenarios. Each scenario consists of one line containing a single number n (1 ≤ n ≤ 10^9). 
 
Output
The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Next, print a single line with the number of distinct solutions of equation (1) for the given value of n. Terminate each scenario with a blank line. 
 
Sample Input
2
4
1260
 
Sample Output
Scenario #1:
3
Scenario #2:
113

以前留下来的题目,今天才补。

题目大意就是给定n求有多少种x,y的组合 使得1/x+1/y=1/n;

因为x,y都大于n,这样我们可以设y=x+k 那么上边的等式可以化成x=n*n/k+n;

问题变成求有多少种x了,x是整数,多疑k要是n*n的因子才行.

由于任意一个数都可以表示成 n=p1^r1*p2^r2*p3^r3.....pi^ri 这种形式(其中pi是素数),那么因子的数量就是(r1+1)*(r2+1)*(r3+1)....*(ri+1).(因为每种pi可以选择ri个嘛也可以不选)

那么 n*n的因子数呢?  同理可得n*n的因子数为(2*r1+1)*(2*r2+1)*(2*r3+1)....*(2*ri+1)个

/* ***********************************************
Author :guanjun
Created Time :2016/10/9 18:38:22
File Name :hdu1299.cpp
************************************************ */
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
int n;
int prime[];
int vis[];
int num;
void init(){
num=;
memset(vis,,sizeof vis);
int x=sqrt()+;
for(int i=;i<=x;i++){
if(!vis[i]){
prime[++num]=i;
for(int j=i;j<=x;j+=i)vis[j]=;
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
init();
int t;
cin>>t;
for(int k=;k<=t;k++){
scanf("%d",&n);
ll ans=;
int p,cnt;
for(int i=;i<=num;i++){
p=prime[i];
cnt=;
if(p*p>n)break;
while(n%p==){
cnt++;
n/=p;
}
ans*=(*cnt+);
}
if(n>)ans*=;
printf("Scenario #%d:\n",k);
printf("%lld\n\n",(ans+)/);
}
return ;
}

真是醉了,筛素数的时候,x=100000和10000是  num会出现诡异的变化....科学事故啊

HDU 1299Diophantus of Alexandria的更多相关文章

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

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

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

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

  3. hdu 1299 Diophantus of Alexandria (数论)

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

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

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

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

  6. hdoj 1299 Diophantus of Alexandria

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

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. VMware 12虚拟机下Ubuntu 16连不上网解决方法

    打开自带Firefox浏览器,显示连接不上网,终端下 ping 也显示 unkown   解决方法: 1.打开虚拟机的“编辑”选项,选择“虚拟网络编辑器” 2.选择VMnet8(我不知道为啥VMnet ...

  2. #NOIP前数学知识总结

    我好菜啊…… 欧拉函数 欧拉函数φ(n),是小于n且和n互质的正整数(包括1)的个数. 性质: 1.对于质数n: φ(n)=n-1 2..对于n=pk φ(n)=(p-1)*pk-1 3.积性函数的性 ...

  3. vue组件---组件注册

    (1)组件名 在注册一个组件的时候,我们始终需要给它一个名字.比如在全局注册的时候我们已经看到了: Vue.component('my-component-name', { /* ... */ }) ...

  4. 40条常见的移动端Web页面问题解决方案

    1.安卓浏览器看背景图片,有些设备会模糊.想让图片在手机里显示更为清晰,必须使用2x的背景图来代替img标签(一般情况都是用2倍).例如一个div的宽高是100100,背景图必须得200200,然后b ...

  5. 【解题报告】洛谷 P2571 [SCOI2010]传送带

    [解题报告]洛谷 P2571 [SCOI2010]传送带今天无聊,很久没有做过题目了,但是又不想做什么太难的题目,所以就用洛谷随机跳题,跳到了一道题目,感觉好像不是太难. [CSDN链接](https ...

  6. 洛谷——P2827 蚯蚓

    P2827 蚯蚓 题目描述 本题中,我们将用符号 \lfloor c \rfloor⌊c⌋ 表示对 cc 向下取整,例如:\lfloor 3.0 \rfloor = \lfloor 3.1 \rflo ...

  7. HDU - 2044 - 一只小蜜蜂...(dp)

    题意: 如题 思路: 仔细观察图 1-4和3-6其实是一样的答案,那么所有的方案都可以相减,意思为全部转化为从1开始 剩下的就是观察规律,仔细观察5号,能到5号蜂房的只有3和4,3和4到5号蜂房只有一 ...

  8. MySQL Docker方式安装

    以5.7版本为例 1 配置mysql配置文件编辑/etc/my.cnf,添加以下内容: [mysqld] skip-host-cache skip-name-resolve datadir=/var/ ...

  9. Spring AOP学习(六)

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  10. 有关HTML的相关基础问题:

    有关HTML的相关基础问题:1.Doctype作用?严格模式与混杂模式如何区分?它们有何意义?   1)<!DICTYPE>声明位于文档中的最前面,处于<html>标签之前,告 ...