UVA 10892 LCM Cardinality
来源:互联网 发布:什么是根域名服务器 编辑:程序博客网 时间:2024/05/19 04:54
Question:
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,让你找出LCM(a,b)=n的对数(a<=b).
思路:这题比较简单,只需要找出给出数n的因子即可,将其推入一个数组,再对数组进行操作,找出p[i]*p[j]/gcd(p[i],p[j])==n的对数
(http://acm.hust.edu.cn/vjudge/contest/121559#problem/D)
#include <iostream>#include <cstdio>#include <vector>#include <cmath>using namespace std;typedef long long LL;vector <LL> p;LL gcd(LL a,LL b){ if(b==0) return a; else return gcd(b,a%b);}int main(){ LL n,num; while (1) { num=0; scanf("%lld",&n); if(n==0) break; for(LL i=1;i<=sqrt(n);i++) { if(i==sqrt(n)) p.push_back(i); //一个因子只需要推入一次即可,此操作避免重复重复推入一个因子 else if(n%i==0) { p.push_back(i); p.push_back(n/i); } } for(int i=0;i<p.size();i++) { for(int j=i;j<p.size();j++) { if(p[i]*p[j]/gcd(p[i],p[j])==n) num++; } } printf("%lld %lld\n",n,num); p.clear(); } 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(数论 质因数分解)
- unity树形结构(Script Based Runtime Tree-View Control)
- Java Map集合遍历的三种方法
- 虚拟机文件共享
- eclipse快捷键 包括查找类、方法、变量
- Android 命名规范和编码规范(尽力简单,多写注释)
- UVA 10892 LCM Cardinality
- HSV颜色到RGB的转换C++代码 直接可用
- 智慧旅游的c端产品破局
- python-pickle/cPickle/glob/tarfile
- 用opencv自带的traincascade车辆检测
- 【POJ2286】The Rotation Game
- 关于我
- java打印文件夹以及文件的路径打印
- 【结论】【状压DP】