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 ...
随机推荐
- tab切换 -- vue
效果: html: // 按钮<div class="orderTab clearfix" @click="toggle()"> <div c ...
- PAT甲级——A1090 Highest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- 05-python 学习第五天,简易聊天工具(shelve模块练习)
需求:1.有两个用户,一个是mychat.py,另一个是youchat.py2.通过执自己的文件,可以看到对方输入的内容,实现连个命令行窗口之间聊天的功能.3.通过shelve 持久化写入和和读取功能 ...
- 通过实体类生成建表SQL语句实现方法
import java.io.File; import java.io.FileOutputStream; import java.lang.reflect.Field; import java.ut ...
- Tomcat Add and Remove 项目时提示 Project facet Java version 1.8 is not supported 错误
原因:项目的jdk和tomcat的jdk版本不同 将eclipse-preference-server-runtime environments 点击你要用的tomcat 点击 edit-jre选择和 ...
- intellij idea中去除@Autowired注入对象带来的下划线提示
场景: idea中通过@Autowired注入的对象一直有下划线提示,虽然不影响运行 解决:改变@Autowired的检查级别即可. 快捷键:Ctrl+Alt+s,进入idea设置界面,输入inspe ...
- MySQL的高可用实现方案之mysql-mmm
一.环境简述 1.工作逻辑图 2.MySQL-MMM优缺点 优点:高可用性,扩展性好,出现故障自动切换,对于主主同步,在同一时间只提供一台数据库写操作,保证的数据的一致性. 缺点:Monitor节点是 ...
- deepfake安装python常用命令
pip install -r requirements.txt -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/ python -m p ...
- 阿里云 Aliplayer高级功能介绍(六):进度条标记
基本介绍 Aliplayer在进度条上提示时间和缩略图功能外,还可以进行视频内容的提示打点,当然不止是进度条上显示打点的内容,还提供一组接口,方便用户进行打点时间和内容的获取, 基本UI如下图所示: ...
- C语言复制数组
直接上代码,分别是栈上开辟内存,堆上开辟内存 #include <stdio.h> #include <stdlib.h> void test01(){ ]; printf(& ...