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? 如果有的话,输出字典序最小的路径 ...
随机推荐
- 关于Java的this关键字
java中的this随处可见,用法也多,现在整理有几点: 1. this是指当前对象自己. 当在一个类中要明确指出使用对象自己的的变量或函数时就应该加上this引用.如下面这个例子中: public ...
- struts2-ajax-jQuery
1.所需jar包如下所示.其中选中的四个包是struts2实现ajax所必需的,所有的jar包都可以从下载的完整的struts2 包中的lib文件夹中找到. 2.Demo struts2ajax.js ...
- 在Ubuntu下配置Apache多域名服务器
1. 目标: 在本机 实现访问不同域名 可以访问不同的目录. 即:访问a.com 进入 /var/www/a 目录下的程序,访问b.com 进入/var/www/b目录下的程序. 2.遇到的问题: / ...
- asp.net页面与页面之间传参数值
一.利用POST传值 传值asp文件send.aspx 代码如下 复制代码 <form id="form1" runat="server" action ...
- Cocos2d-x加速度计实例:运动的小球
下面我们通过一个实例介绍一下如果通过层加速度计事件实现访问加速度计.该实例场景如下图所示,场景中有一个小球,当我们把移动设备水平放置,屏幕向上,然后左右晃动移动设备来改变小球的位置. 下面我们再看看具 ...
- 快速搭建MongoDB分布式集群
目录Outline 1. prerequisites 2. steps to follow3. configuring the cluster4. a little test to see 1. Pr ...
- 提升程序的特权(AdjustTokenPrivileges)
首先列出需要的函数 1.OpenProcessToken 2.AdjustTokenPrivileges 3. LookupPrivilegeValue ----------------------- ...
- Eclipse必须掌握的快捷键
Eclipse快捷键 Ctrl + / 添加//注释.删除//注释 Ctrl + 1 快速修复错误 Ctrl + Shift + f 格式化文档 Shift + Enter Shift + Ctrl ...
- javascript 文本框中,判断回车键触发事件 兼容IE&FireFox
1.onkeypress&onkeydown区别 onkeypress 事件在用户按下并放开任何字母数字键时发生.但是系统按钮(例如:箭头键.功能键)无法得到识别. onkeydown 事件在 ...
- jQuery插件开发 - 其实很简单
[前言] jQuery已经被广泛使用,凭借其简洁的API,对DOM强大的操控性,易扩展性越来越受到web开发人员的喜爱,我在社区也发布了很多的jQuery插件,经常有人询问一些技巧,因此干脆写这么一篇 ...