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 ...
随机推荐
- 每日学习心得:SQL查询表的行列转换/小计/统计(with rollup,with cube,pivot解析)
2013-8-20 1. SQL查询表的行列转换/小计/统计(with rollup,with cube,pivot解析) 在实际的项目开发中有很多项目都会有报表模块,今天就通过一个小的SQL ...
- mysql frm的恢复,data里只有frm文件的恢复
mysql frm的恢复,data里只有frm文件的恢复 mysql frm的恢复,data里只有frm文件的恢复,换了系统,装了windows2003,重装最新5.4版的mysql,把原来的一个数据 ...
- HTML 链接
HTML 使用超级链接与网络上的另一个文档相连. 几乎可以在所有的网页中找到链接.点击链接可以从一张页面跳转到另一张页面. 实例 创建超级链接 本例演示如何在 HTML 文档中创建链接. 将图像作为链 ...
- sql 操作,
SELECT * FROM dbo.tbl_Web_Photos AS pt LEFT JOIN dbo.tbl_Web_Friends AS fd ON pt.user_email=fd.AddEm ...
- Python哈希函数hashlib
hashlib常用加密方法:md5(), sha1(), sha224(), sha356(), sha384(), sha512()等 结果显示方法: digest(): 返回二进制字符串 h ...
- android如何播放资源文件夹raw中的视频
转自这里 videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/&qu ...
- 在Ubuntu下编译wpa_supplicant
最近在研究WiFi联盟的多屏互动协议Miracast,其中需要用到wpa_supplicant,编译中遇到了一些问题,经过一下午的折腾也都解决了,下面分享给各位. 一.编译需要用到三个库源码包,分别是 ...
- IOS中UIWebView停止加载
方法一: [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank" ...
- html元素的显示和隐藏
div的visibility可以控制div的显示和隐藏,但是隐藏后页面显示空白: style="visibility: hidden;" document.getElementBy ...
- Report_客制化报表输出Excel后去0问题(案例)
2014-02-01 Created By BaoXinjian