UVA 10892 LCM Cardinality 数学
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
题意:给你m,求出多少对 数的LCM(a,b)=m
题解:必然是M的因子,我们对M求因子,我们知道因子特别少,我们就两层循环暴力去找对子就好了
//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
#include<vector>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = ;
const int M = ;
const int inf = 0x3f3f3f3f;
const int MOD = ;
const double eps = 0.000001; int main() {
ll n;vector<ll >G;
while(~scanf("%lld",&n)) {
if(n == ) break;
if(n == ) {
cout<<<<" "<<<<endl;continue;
}
ll ans = ;
ll aim = n;
G.clear();
G.pb(n);G.pb();
for(ll i=;i*i<=n;i++) {
if(n%i==) {
G.pb(i);if(n/i!=i) G.pb(n/i);
}
}
sort(G.begin(),G.end());
for(int i=;i<G.size();i++)
for(int j=i;j<G.size();j++) {
ll a = G[i];
ll b = G[j];
if(a*b/__gcd(a,b) == aim)
ans++;//,cout<<a<<" "<<b<<endl;
}
cout<<aim<<" "<<ans<<endl;
}
return ;
}
代码
UVA 10892 LCM Cardinality 数学的更多相关文章
- UVA 10892 - LCM Cardinality
Problem F LCM Cardinality Input: Standard Input Output: Standard Output Time Limit: 2 Seconds A pair ...
- 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 ...
- UVA 11388-GCD LCM(数学)
I I U C O N L I N E C Problem D: GCD LCM Input: standard input Output: standard output The GCD ...
- 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 10288 - Coupons(数学期望 + 递推)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- MySQL使用rand函数实现随机数[转]
如何写一个语句能一下更新几百条MYSQL数据! 需要测试MYSQL数据库,里面有一个上万条数据的数据库,如何写一个PHP文件一下每次更新几百条信息,我都是写一个循环一次更新一条信息,这样我知道用WHI ...
- c/c++常用代码 -- 共享内存
#pragma once #include <stdio.h> #include <tchar.h> #include <string.h> #include &l ...
- IIS8 web.config 重定向之后 报错 500.19
原因是没有安装 URL Rewrite 官方下载地址:http://www.iis.net/downloads/microsoft/url-rewrite#additionalDownloads
- Python实现LR(逻辑回归)
Python实现LR(逻辑回归) 运行环境 Pyhton3 numpy(科学计算包) matplotlib(画图所需,不画图可不必) 计算过程 st=>start: 开始 e=>end o ...
- 网络笔记02数据解析 -1-JSON解析
1.JSON解析 1.JSON介绍 JSON是最网络传输数据最为广泛的数据格式,没有之一,出身草根,是Javascript的子集,专门负责描述数据格式.Javascript是网页开发的一种脚本语言,和 ...
- P1699: [Usaco2007 Jan]Balanced Lineup排队
很明显是一道RMQ问题,倍增法,维护一下区域的最大/小值就行了. var n,i,j,q,f,t,times:longint; hmin,hmax:array[..,..] of longint; f ...
- 一次我们网站的web性能优化
1.Google的Web优化最佳实践 利用PageSpeed工具 对我们红酒世界网进行检测时,发现了下面的几个问题 1.Leverage browser caching 1.1.通过web.confi ...
- 使用cronolog切割tomcat catalina.out文件
今天查看之前配置的tomcat发现catalina.out文件已经增大到接近5G,过不了多久就会将所在分区撑爆. 搜集了一下,大部分都使用cronolog切割catalina.out文件.按照这个方式 ...
- ELK kibana查询与过滤(17th)
在kibana中,可通过搜索查询过滤事务或者在visualization界面点击元素过滤. 创建查询 在Discover界面的搜索栏输入要查询的字段.查询语法是基于Lucene的查询语法.允许布尔运算 ...
- BZOJ 4500: 矩阵 差分约束
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=4500 题解: 从行向列建边,代表一个格子a[i][j],对每个顶点的所有操作可以合并在一 ...