UVA 10892 - LCM Cardinality
Problem F LCM Cardinality Input: Standard Input
Output: Standard Output
Time Limit: 2 Seconds
A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible pairs. For example 12 is the LCM of (1, 12), (2, 12), (3,4) etc. For a given positive integer N, the number of different integer pairs with LCM is equal to N can be called the LCM cardinality of that number N. In this problem your job is to find out the LCM cardinality of a number.
<!--[if !supportEmptyParas]--> <!--[endif]-->
Input
The input file contains at most 101 lines of inputs. Each line contains an integer N (0<N<=2*109). Input is terminated by a line containing a single zero. This line should not be processed.
<!--[if !supportEmptyParas]--> <!--[endif]-->
Output
For each line of input except the last one produce one line of output. This line contains two integers N and C. Here N is the input number and C is its cardinality. These two numbers are separated by a single space.
<!--[if !supportEmptyParas]--> <!--[endif]-->
Sample Input Output for Sample Input
2 12 24 101101291 0 |
2 2 12 8 24 11 101101291 5 |
#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
const int M= ;
bool isprime[M+] ;
int prime[M] ,id;
void make_prime(){
id= ;
memset(isprime,,sizeof(isprime)) ;
for(int i=;i<=M;i++){
if(!isprime[i])
prime[++id]=i ;
for(int j=;j<=id&&prime[j]*i<=M;j++){
isprime[i*prime[j]]= ;
if(i%prime[j]==)
break ;
}
}
}
LL gao(LL x){
LL sum ;
LL ans= ;
for(int i=;i<=id&&prime[i]*prime[i]<=x;i++){
if(x%prime[i]==){
sum= ;
while(x%prime[i]==){
sum++ ;
x/=prime[i] ;
}
ans=ans*(sum+sum+) ;
}
if(x==)
break ;
}
if(x!=)
ans*= ;
return (ans+)>> ;
}
int main(){
LL x ;
make_prime() ;
while(cin>>x&&x){
cout<<x<<" "<<gao(x)<<endl ;
}
return ;
}
UVA 10892 - LCM Cardinality的更多相关文章
- UVA 10892 LCM Cardinality 数学
A pair of numbers has a unique LCM but a single number can be the LCM of more than one possiblepairs ...
- UVA 10892 LCM Cardinality(数论 质因数分解)
LCM Cardinality Input: Standard Input Output: Standard Output Time Limit: 2 Seconds A pair of number ...
- UVA 10892 - LCM Cardinality(数学题)
题目链接 写写,就ok了. #include <cstdio> #include <cstring> #include <string> #include < ...
- Uva 10892 LCM Cardinality (数论/暴力)
题意:给出数n,求有多少组A,B的最小公约数为n; 思路:3000ms,直接暴力寻找,找到所有能把n整除的数 pi, 枚举所有pi 代码: #include <iostream> #inc ...
- LCM Cardinality 暴力
LCM Cardinality Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit St ...
- UVa 10892 (GCD) LCM Cardinality
我一直相信这道题有十分巧妙的解法的,去搜了好多题解发现有的太过玄妙不能领会. 最简单的就是枚举n的所有约数,然后二重循环找lcm(a, b) = n的个数 #include <cstdio> ...
- LCM Cardinality UVA - 10892(算术基本定理)
这题就是 LightOJ - 1236 解析去看这个把https://www.cnblogs.com/WTSRUVF/p/9185140.html 贴代码了: #include <iostrea ...
- uva 10892
试了一下纯暴力 结果过了 无话可说 应该有更好的方法...... /**************************************************************** ...
- LCM Cardinality
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=31675#problem/E 暴力 // File Name: uva10892.cpp ...
随机推荐
- ASP.NET Web API实践系列04,通过Route等特性设置路由
ASP.NET Web API路由,简单来说,就是把客户端请求映射到对应的Action上的过程.在"ASP.NET Web API实践系列03,路由模版, 路由惯例, 路由设置"一 ...
- php 连接测试sphinx
shpinx.php <?php header("Content-type:text/html;charset=utf-8"); include 'SphinxClient. ...
- (转)VS.NET2010水晶报表安装部署[VS2010]
本文转载自:http://www.cnblogs.com/xiaofengfeng/p/3325793.html 欢迎C#高手加盟QQ群:9340166 水晶报表VS2010版IDE安装标准版SAP ...
- 战胜忧虑<2>——忙碌可以消除忧虑
忙碌可以消除忧虑 当你的脑筋空出来时,也会有东西进去补充,是什么呢?通常都是你的感觉.为什么?因为忧虑.恐惧.憎恨.嫉妒.和羡慕等等情绪,都是由我们的思想所控制的,这种情绪都非常猛烈.会把我们思想中所 ...
- sublime安装DocBlockr注释插件
点击sublime的菜单栏 view->show console :现在打开了控制台, 这个控制台有上下两栏, 上面一栏会实时显示sublime执行了什么插件,输出执行结果, 如果你安装的某个插 ...
- 使用BlockingQueue的生产者消费者模式
BlockingQueue很好的解决了多线程中,如何高效安全“传输”数据的问题.通过这些高效并且线程安全的队列类,为我们快速搭建高质量的多线程程序带来极大的便利.使用场景. 首先它是一个队列,而一个队 ...
- PLSQL_Oracle PLSQL处理日期方式大全(概念)
TO_DATE格式 Day: dd number 12 dy abbreviated fri day spelled out friday ddspth spelled out, ordin ...
- 0808HTML
打开DREAMWEAVER,新建HTML,页面上有几句代码 <html>开始标签 <head>网页上的控制信息 <title>页面标题</title> ...
- git的使用(3) 多分支情况下的pull
当你存在多个分支的时候,你需要pull下来分支上面的内容,你需要指定分支进行同步命令: git pull origin branch (branch 是你的分支的名字)
- 在windows下添加php的Imagick扩展
安装ImageMagick-6.9.2-6-Q16-x64-dll.exe 将安装目录下的CORE_开头的dll文件和X11.dll文件复制到c:\windows\system32\下, 在windo ...