UVA-10892 LCM Cardinality
来源:互联网 发布:centos 7 安装desktop 编辑:程序博客网 时间:2024/05/19 02:42
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.
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.
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.
Sample Input
2
12
24
101101291
0
Sample Output
2 2
12 8
24 11
101101291 5
分析:将n质因数分解,得到n=lcm(a,b)=(p1^r1)(p2^r2)(p3^r3)…(pm^rm),pm小于n。其中,ri=max(ai,bi)。若ai=ri,则bi有ri+1种可能性,若bi=ri,则ai有ri+1种可能性,除去ai=bi=ri,总共有2*ri+1种情况。若n是素数,则ri=0。由于a,b可以互换,则ans=ans/2+1(考虑a=b)。
Source:
#include<stdio.h>int main(){ int n,m,c,p,count,ans; while(scanf("%d",&n)!=EOF) { if(n==0) return 0; m=n; ans=1; for(p=2;p<n;p+=2) //质因数分解 { count=0; while(n%p==0) { count++; n/=p; } ans*=2*count+1; if(p==2) p--; } if(n>1) //考虑n是素数的情况 ans*=3; ans=ans/2+1; //除去a=b的情况 printf("%d %d\n",m,ans); } return 0;}
- UVa:10892 LCM Cardinality
- UVA 10892-LCM Cardinality
- UVa 10892 - LCM Cardinality
- UVA 10892 - LCM Cardinality
- UVA 10892 LCM Cardinality
- uva 10892 LCM Cardinality
- UVa-10892 LCM Cardinality
- UVA-10892 LCM Cardinality
- LCM Cardinality(UVA 10892)
- uva 10892 - LCM Cardinality(数论)
- UVA 10892 - LCM Cardinality(数论)
- UVA - 10892 LCM Cardinality (枚举因子)
- UVA 10892 LCM Cardinality (因子分解 水题)
- UVa 10892 LCM Cardinality (数论+组合数学)
- UVa 10892 LCM Cardinality (数论&素因子分解)
- Uva 10892 - LCM Cardinality 解题报告(因式分解)
- UVa 10892 - LCM Cardinality (因式分解 组合数学)
- UVA 10892 LCM Cardinality(数论 质因数分解)
- 《effective c++》条款二:尽量以enum,const,inline替换#define
- 第七章-更加抽象——python基础教程(第二版)笔记
- 未完成题目
- 八卦基督教和穆斯林(转)
- python3 ORM重难点
- UVA-10892 LCM Cardinality
- 【VS2013】目录结构,文件的组成结构
- 上手LaTeX-基本文档结构
- Spring 入门 上 (xml 配置方式)
- Ubuntu下配置Anaconda
- 透光软膜规格尺寸
- jxls2.3-简明教程
- 第一阶段项目小结
- Problem B. gWheels Google APAC 2016 University Test Round B