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 xn + yn = zn. 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)
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:
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 nquickly?
Input
The first line contains the number of scenarios. Each scenario consists of one line containing a single number n (1 ≤ n ≤ 109).
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<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>
const int maxn=1e5+;
typedef long long ll;
using namespace std; int prime[];
bool vis[];
int cnt =;
void erla() { memset(vis,false,sizeof(vis));
memset(prime,,sizeof(prime));
for(int t=; t<=; t++) {
if(!vis[t]) {
prime[cnt++]=t;
}
for(int j=; j<cnt&&t*prime[j]<=; j++) {
vis[t*prime[j]]=true;
if(t%prime[j]==) {
break;
}
}
}
} int main()
{
int T;
erla();
cin>>T;
int ca=;
while(T--)
{
int n;
scanf("%d",&n);
ll ans=;
for(int t=;t<cnt;t++)
{
ll s1=;
while(n%prime[t]==)
{
n/=prime[t];
s1++;
}
ans=ans*(*s1+);
if(n==)
{
break;
}
}
if(n!=)
ans*=;
ans=(ans+)/;
printf("Scenario #%d:\n",ca++);
printf("%lld\n\n",ans);
}
return ;
}
Diophantus of Alexandria(唯一分解定理)的更多相关文章
- NOIP2009Hankson 的趣味题[唯一分解定理|暴力]
题目描述 Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫 Hankson.现 在,刚刚放学回家的 Hankson 正在思考一个有趣的问题. 今天在课堂上,老师讲 ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- uva10375 Choose and Divide(唯一分解定理)
uva10375 Choose and Divide(唯一分解定理) 题意: 已知C(m,n)=m! / (n!*(m-n!)),输入整数p,q,r,s(p>=q,r>=s,p,q,r,s ...
- hdu 1299 Diophantus of Alexandria (数论)
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 题目大意: 给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. ...
- UVA 10375 Choose and divide【唯一分解定理】
题意:求C(p,q)/C(r,s),4个数均小于10000,答案不大于10^8 思路:根据答案的范围猜测,不需要使用高精度.根据唯一分解定理,每一个数都可以分解成若干素数相乘.先求出10000以内的所 ...
- 唯一分解定理 poj 1365
一行代表一个数 x 给你底数和指数 求x-1的唯一分解定理的底数和指数 从大到小输出 #include<stdio.h> #include<string.h> #include ...
- Diophantus of Alexandria[HDU1299]
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- UVA294DIvisors(唯一分解定理+约数个数)
题目链接 题意:输入两个整数L,U(L <= U <= 1000000000, u - l <= 10000),统计区间[L,U]的整数中哪一个的正约数最多,多个输出最小的那个 本来 ...
随机推荐
- 22-关键字:super
1.super 关键字可以理解为:父类的 2.可以用来调用的结构: 属性.方法.构造器 3.super调用属性.方法: 3.1 我们可以在子类的方法或构造器中.通过使用"super.属性&q ...
- 解惑4:java是值传递还是引用传递
一.概述 曾经纠结了很久java的参数传递方式是什么样的,后面粗略的了解了一鳞半爪以后有了大概的印象:"传参数就是值传递,传对象就是引用传递",后面进一步查找了相关资料和文章以后, ...
- myBatis源码解析-数据源篇(3)
前言:我们使用mybatis时,关于数据源的配置多使用如c3p0,druid等第三方的数据源.其实mybatis内置了数据源的实现,提供了连接数据库,池的功能.在分析了缓存和日志包的源码后,接下来分析 ...
- Make Windows 10 Comfortable
在 StartUp 目录中(在当前用户目录下), 创建.bat, 里面可以写希望登录指定的命令(如使用subst进行映射, 将常用的目录映射为磁盘驱动器) 在 %USERPROFILE%(也就是用户家 ...
- 在Linux系统中安装Tomcat详细教程
首先在官网下载jdk和Tomcat的压缩包 这里下载jdk-8u241-linux-x64 .tar.gz 和apache-tomcat-8.5.50.tar.gz 然后解压jdk压缩包 tar –z ...
- SCHP代码中的问题
1.subprocess.CalledProcessError: Command ‘[‘where’, ‘cl’]’ returned non-zero exit status 1. 这个问题是因为电 ...
- 企业级Gitlab-ci实践
前言 吐槽一波 2020年6月2号刚入职公司时,第一感觉是集群环境是个大坑!内网一套,公网一套.内网采用单节点Kubernetes,公网采用aliyun托管的X节点Kubernetes(还有节点是2C ...
- TCP学习指北
限于博主水平有限不敢说指南,但应该能够避免刚学TCP的同学出现找不着北的情况. TCP与UDP的区别 区别: UDP是无连接的,而TCP是面向连接的,传数据前要先建立连接. UDP可以一对多,多对多通 ...
- effective java之使用构建器来创建对象
第二章第2条:遇到多个构造器参数时要考虑使用构建器(builder) 就是建造者模式(不直接生成想要的对象,而是让客户端利用所有有必要的参数调用构造器或者静态工厂)直接上代码 package com. ...
- Xor 思维题
Xor 思维题 题目描述 小\(Q\)与小\(T\)正在玩一棵树.这棵树有\(n\)个节点,编号为 \(1\),\(2\) \(3...n\),由\(n-1\)条边连接,每个节点有一个权值\(w_i\ ...