uva 10892
试了一下纯暴力 结果过了 无话可说 应该有更好的方法......
/*************************************************************************
> Author: xlc2845 > Mail: xlc2845@gmail.com
> Created Time: 2013年10月26日 星期六 10时15分23秒
************************************************************************/ #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#define maxn 210
#define INF 0x7fffffff
#define longlong LL
using namespace std; int gcd(int a, int b)
{
return b == 0 ? a : gcd(b, a%b);
} int lcm(int a, int b)
{
return a / gcd(a, b)*b;
} int n, a[1000000], k, ans; int main()
{
while(scanf("%d",&n) && n)
{
k = ans = 0;
for(int i = 1; i <= sqrt(n+0.1); i++)
{
if(n%i == 0)
{
a[k++] = i;
a[k++] = n/i;
}
}
if(a[k-1] == a[k-2]) //不能少
k--;
for(int i = 0; i < k; i++)
for(int j = i; j < k; j++)
if(lcm(a[i], a[j]) == n)
ans++;
printf("%d %d\n", n, ans);
}
return 0;
}
uva 10892的更多相关文章
- UVA 10892 - LCM Cardinality(数学题)
题目链接 写写,就ok了. #include <cstdio> #include <cstring> #include <string> #include < ...
- UVA 10892 - LCM Cardinality
Problem F LCM Cardinality Input: Standard Input Output: Standard Output Time Limit: 2 Seconds A pair ...
- 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 (GCD) LCM Cardinality
我一直相信这道题有十分巧妙的解法的,去搜了好多题解发现有的太过玄妙不能领会. 最简单的就是枚举n的所有约数,然后二重循环找lcm(a, b) = n的个数 #include <cstdio> ...
- UVA 10892 LCM Cardinality(数论 质因数分解)
LCM Cardinality Input: Standard Input Output: Standard Output Time Limit: 2 Seconds A pair of number ...
- Uva 10892 LCM Cardinality (数论/暴力)
题意:给出数n,求有多少组A,B的最小公约数为n; 思路:3000ms,直接暴力寻找,找到所有能把n整除的数 pi, 枚举所有pi 代码: #include <iostream> #inc ...
- LCM Cardinality UVA - 10892(算术基本定理)
这题就是 LightOJ - 1236 解析去看这个把https://www.cnblogs.com/WTSRUVF/p/9185140.html 贴代码了: #include <iostrea ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
随机推荐
- bootstrap学习起步篇:初识bootstrap之html5语法构建hello篇(一)
目前选择使用bootstrap作为前端页面模板,是件很省心的事情.官网上给出的实例和教程也很多.在实际使用过程中,我们也许还要借助文档去了解它的元素和样式.但也不能减少我们使用他的兴趣. 我准备将其整 ...
- iOS 之美:iOS Delegate 使用五步曲
在iOS 开发中, 搞清楚Delegate 是需要花些时间的. Delegate 本来是软件架构设计的一种理念.对于像手机这样一个有限的设备,我们需要充分考虑到:内存要尽量省着用: 视图之间的关系要清 ...
- android使用Intent操作拨打号码发送短信
Activity程序Activity.java package com.example.intentcaseproject; import android.net.Uri; import androi ...
- Android Studio 创建aar包与引用
两者区别:*.jar: 只包含了class文件与清单文件 ,不包含资源文件,如图片等所有res中的文件.*.aar: 包含所有资源 ,class以及res资源文件全部包含 一.创建aar包1.创建一个 ...
- Java集合类 java.util包
概述 软件包 类 使用 树 已过时 索引 帮助 JavaTM Platform Standard Ed. 6 上一个软件包 下一个软件包 框架 无框架 ...
- dreamweaver中用正则表达式查找替换批量删除 tppabs标签的方法
查找替换 正则表达式 \btppabs="h[^"]*" 后面不能有空格 你懂得的 选中右下角的 √[使用正则表达式] 替换全部
- Android之日历触屏测试
结构: 查看运行效果点这里 DiaryTest.apk下载 BaseCalendar: package com.cdp.Activity; import java.util.Calendar; imp ...
- Cocos开发中Visual Studio下libcurl库开发环境设置
我们介绍一下win32中Visual Studio下libcurl库开发环境设置.Cocos2d-x引擎其实已经带有为Win32下访问libcurl库,Cocos2d-x 3.x中libcurl库文件 ...
- Html的maxlength属性
maxlength表示文本框只能输入的字符串,多的无法输入
- OCI下报出的数据库重账错
[2014-01-09 19:43:45.469220][22347888] Level 0 COCITOOL: Error - OCI_ERROE - errcode[1],errmsg[ORA-0 ...