数学--数论--HDU 1299 +POJ 2917 Diophantus of Alexandria (因子个数函数+公式推导)
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
#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e5 + 5;
int n;
long long ans;
void solve()
{
for (int i = 2; i * i <= n; i++)
{
int cnt = 0;
if (n % i == 0)
{
while (n % i == 0)
{
cnt++;
n /= i;
}
}
if (cnt)
ans *= (long long)(2 * cnt + 1);
}
}
int main()
{
int T;
scanf("%d", &T);
for (int ca = 1; ca <= T; ca++)
{
ans = 1;
scanf("%d", &n);
solve();
if (n > 1)
ans *= 3LL;
printf("Scenario #%d:\n%lld\n\n", ca, (ans + 1)/2);
//这里是说题目中x,y y,x相等,应该除2向上取整
}
}
数学--数论--HDU 1299 +POJ 2917 Diophantus of Alexandria (因子个数函数+公式推导)的更多相关文章
- POJ 2992 Divisors (求因子个数)
题意:给n和k,求组合C(n,k)的因子个数. 这道题,若一开始先预处理出C[i][j]的大小,再按普通方法枚举2~sqrt(C[i][j])来求解对应的因子个数,会TLE.所以得用别的方法. 在说方 ...
- 数学--数论--HDU - 6395 Let us define a sequence as below 分段矩阵快速幂
Your job is simple, for each task, you should output Fn module 109+7. Input The first line has only ...
- 数学--数论--HDU 2582 F(N) 暴力打表找规律
This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gc ...
- 数学--数论--HDU 2802 F(N) 公式推导或矩阵快速幂
Giving the N, can you tell me the answer of F(N)? Input Each test case contains a single integer N(1 ...
- 数学--数论--HDU 12151七夕节 Plus (因子和线性筛)
Problem Description 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" ...
- 数学--数论--HDU - 6322 打表找规律
In number theory, Euler's totient function φ(n) counts the positive integers up to a given integer n ...
- 数学--数论--hdu 5878 I Count Two Three(二分)
I will show you the most popular board game in the Shanghai Ingress Resistance Team. It all started ...
- 数学--数论-- HDU 2601 An easy problem(约束和)
Problem Description When Teddy was a child , he was always thinking about some simple math problems ...
- 数学--数论--hdu 6216 A Cubic number and A Cubic Number (公式推导)
A cubic number is the result of using a whole number in a multiplication three times. For example, 3 ...
随机推荐
- 家庭记账本app进度之复选框以及相应滚动条的应用
这次主要是对于android中复选框的相应的操作.以及其中可能应用到的滚动条的相关应用.每一个复选框按钮都要有一个checkBox与之相对应. 推荐使用XML配置,基本语法如下:<CheckBo ...
- docker win10 基本指令
一.镜像操作 docker images 本地镜像 docker pull imagename 获取网上获取镜像 docker run 创建docker容器 docker rmi imagename ...
- Linux 用户管理篇(一)
查看当前在线的用户 who 切换不同用户工作界面 ctrl + alt + [F1 - F6] 切换图形界面 ctrl + alt + F7 注消用户 exit ...
- AJ学IOS 之CoreLocation地理编码小Demo输入城市得到经纬度
AJ分享,必须精品 一:效果 输入地名,可以得到相应的经纬度,知识为了学习写的小Demo 二:实现步骤 一 :首先获取用户输入的位置. 二 :创建地理编码对象. 三 :利用地理编码对象编码,根据传入的 ...
- python填写问卷星,疫情上报
#!!!注意:修改main里的url为真实的url,按需修改 50行 set_data中的submitdata # 61行 ip 修改为 真ip # submittype可能有错误,在151行 # 提 ...
- springboot集成JdbcTemplate+druid
application.yml datasource: username: root password: root url: jdbc:mysql://localhost:3306/early_war ...
- 19.SpringCloud实战项目-SpringCloud整合Alibaba-Nacos配置中心
SpringCloud实战项目全套学习教程连载中 PassJava 学习教程 简介 PassJava-Learning项目是PassJava(佳必过)项目的学习教程.对架构.业务.技术要点进行讲解. ...
- 2.hover的使用
1. 自身的hover div :hover{ :hover前要有空格 } 2.hover指向子元素 father:hover .childer { :hover前不能有空格 } 3.ho ...
- SpringMVC视图解析中的 forward: 与 redirect: 前缀
在 SpringMVC 中,可以指定画面的跳转方式.使用 forward: 前缀实现请求转发跳转,使用 redirect: 前缀实现重定向跳转.有前缀的转发和重定向操作和配置的视图解析器没有关系,视图 ...
- blink测试技术介绍
引言: flink是面向数据流处理和批处理的分布式开源计算框架.2016年阿里巴巴引入flink框架,改造为blink,将其运用到搜索及推荐的离线实时计算中,成功解决了搜索.推荐实时大数据量计算的痛点 ...