Hdu 1299
Diophantus of Alexandria
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2326 Accepted Submission(s): 887Problem DescriptionDiophantus 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 / 4Clearly, 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?
InputThe first line contains the number of scenarios. Each scenario consists of one line containing a single number n (1 ≤ n ≤ 10^9).OutputThe 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 Input241260Sample OutputScenario #1: 3Scenario #2: 113
/*************************************************************************
> File Name: 1299.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年07月10日 星期四 16时39分38秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; int n;
int prime[];
bool vis[];
int cnt = ; void isPrime() {
cnt = ;
int k = (int)sqrt(1000000000.0) + ;
for (int i = ; i <= k; i++) vis[i] = true;
for (int i = ; i <= k; i++) {
if (vis[i]) {
prime[cnt++] = i;
for (int j = i*i; j <= k; j += i) vis[j] = false;
}
}
} int main(void) {
isPrime();
int c = ;
int t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
int ans = ;
for (int i = ; i < cnt && prime[i] <= n; i++) {
int tmp = ;
while (n % prime[i] == ) {
tmp++;
n /= prime[i];
}
ans *= + * tmp;
}
if (n > ) ans *= ;
printf("Scenario #%d:\n", c++);
printf("%d\n\n", (ans + ) / );
} return ;
}
Hdu 1299的更多相关文章
- hdu 1299 Diophantus of Alexandria(数学题)
题目链接:hdu 1299 Diophantus of Alexandria 题意: 给你一个n,让你找1/x+1/y=1/n的方案数. 题解: 对于这种数学题,一般都变变形,找找规律,通过打表我们可 ...
- 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 (数论)
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+ ...
- 数学--数论--HDU 1299 +POJ 2917 Diophantus of Alexandria (因子个数函数+公式推导)
Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first ma ...
- 求n的因子个数与其因子数之和
方法一:朴素算法:O(n). #include<bits/stdc++.h> using namespace std; int get_num(int n){ ; ;i<=n;++i ...
- HDOJ Problem - 1299
题意:等式 1 / x + 1 / y = 1 / n (x, y, n ∈ N+ (1) 且 x <= y) ,给出 n,求有多少满足该式子的解.(1 <= n <= 1e9) 题 ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- hdu 1573 X问题 (非互质的中国剩余定理)
X问题 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- Cooki and Session
目录 Cookie Cookie的由来 什么是Cookie Cookie的原理 查看Cookie Django中操作Cookie 获取Cookie 设置Cookie 删除Cookie Session ...
- linux操作mysql命令快速手记 — 让手指跟上思考的速度(二)
这一篇是<mysql内建命令快速手记>的姐妹篇,废话不再赘述,直接上干货,跟老铁慢慢品 1.mysql -hlocalhost -uroot -proot,-h,-u,-p分别代表ip,u ...
- JZOJ2368 【SDOI2011】黑白棋
题目 题目大意 在一个1*n的棋盘上,有黑棋和白棋交错分布,每次,一个人可以移动自己的ddd颗旗子. 问先手必胜的方案数. 思考历程 在一开始,我就有点要放弃的念头. 因为这题是一道博弈问题. 我是非 ...
- cf519E
传送门 多组询问,问到树上两个点x,y距离相等的点的个数. 倍增求lca. //Twenty #include<cstdio> #include<cstdlib> #inclu ...
- CGLayer和CALayer区别
CGLayer是一种很好的缓存常绘内容的方法.注意,不要与CALayer混淆.CALayer是Core Animation中更加强大.复杂的图层对象,而CGLayer是Core Graphics中优化 ...
- 记一次server 2008 R2的按装过程
项目上一直在用的dell务器在去年年底突然出现系统过期,导致c盘的东西全部丢失.我们用激活工具激活,还是没能找回丢失的东西. 为了装这个系统,跟同事一起折腾了好些次,最后发现安装服务器的时候有个磁盘阵 ...
- VS 快捷键和正则替换
本文在VS2017中可用 1.注释 :Ctrl K C 取消注释: Ctrl K U 2.整理代码格式: Ctrl K D 或者 Ctrl K F 3.快速切换不同的代码窗口 Ctrl+Tab 4 ...
- PAT甲级——A1049 Counting Ones
The task is simple: given any positive integer N, you are supposed to count the total number of 1's ...
- 关于mybatis-config.xml文件的基础解释
今天是我第一天落户博客园,想一想从mybatis框架开始写起吧.mybatis框架与Hibernate框架相比来说,专注于SQL语句,对SQL语句的要求比较高吧. 我觉得,对于mybatis框架来说, ...
- Django项目: 项目环境搭建 ---- 一、创建django项目
项目环境搭建 一.创建django项目 1.创建python虚拟环境 在虚拟机上创建python虚拟环境,因为实际项目部署,实在linux mkvirtualenv -p /usr/bin/pytho ...