题意:给出数n,求有多少组A,B的最小公约数为n;

思路:3000ms,直接暴力寻找,找到所有能把n整除的数 pi, 枚举所有pi

代码:

#include <iostream>
#include <cstdio>
#include <vector>
#define ll long long
using namespace std; ll gcd(ll a,ll b)
{
if(b==) return a;
else return gcd(b,a%b);
} int main()
{
ll n;
while(cin>>n&&n)
{
vector <ll> p;
for(ll i=; i*i<=n; i++)
{
if(n%i==)
{
p.push_back(i);
if(n/i!=i)
p.push_back(n/i);
}
}
int ans=;
for(ll i=; i<p.size(); i++)
{
for(ll j=i; j<p.size(); j++)
{
if((p[i]*p[j]/gcd(p[i],p[j]))==n)
ans++;
}
}
printf("%lld %d\n",n,ans);
}
return ;
}

Uva 10892 LCM Cardinality (数论/暴力)的更多相关文章

  1. UVA 10892 LCM Cardinality(数论 质因数分解)

    LCM Cardinality Input: Standard Input Output: Standard Output Time Limit: 2 Seconds A pair of number ...

  2. 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 ...

  3. UVA 10892 - LCM Cardinality

    Problem F LCM Cardinality Input: Standard Input Output: Standard Output Time Limit: 2 Seconds A pair ...

  4. UVA 10892 - LCM Cardinality(数学题)

    题目链接 写写,就ok了. #include <cstdio> #include <cstring> #include <string> #include < ...

  5. LCM Cardinality 暴力

    LCM Cardinality Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit St ...

  6. UVA.129 Krypton Factor (搜索+暴力)

    UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...

  7. UVA.10986 Fractions Again (经典暴力)

    UVA.10986 Fractions Again (经典暴力) 题意分析 同样只枚举1个,根据条件算出另外一个. 代码总览 #include <iostream> #include &l ...

  8. 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

    题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...

  9. UVa 10892 (GCD) LCM Cardinality

    我一直相信这道题有十分巧妙的解法的,去搜了好多题解发现有的太过玄妙不能领会. 最简单的就是枚举n的所有约数,然后二重循环找lcm(a, b) = n的个数 #include <cstdio> ...

随机推荐

  1. linux下php调试工具xdebug安装配置

    xdebug简介 Xdebug是php的一款调试工具,是基于zend的一个扩展,可以用来跟踪,调试和分析PHP程序的运行状况.如变量,函数调试,性能监测,代码覆盖率等 xdebug安装 1.下载xde ...

  2. BZOJ 1228: [SDOI2009]E&D(SG定理)

    这道嘛,很容易就看出是个nim和,然后问题就是怎么算子问题的sg函数了 先暴力个表看下规律,很容易就找出来了~~~(百度空间又渣了,图贴不出来= =) 32 0 1 0 2 0 1 0 3 0 1 0 ...

  3. BZOJ 1096: [ZJOI2007]仓库建设(动态规划+斜率优化)

    第一次写斜率优化,发现其实也没啥难的,没打过就随便找了一份代码借(chao)鉴(xi)下,不要介意= = 题解实在是懒得写了,贴代码吧= = CODE: #include<cstdio># ...

  4. Handlebars模板引擎之上手

    handlebars Handlebars,一个JavaScript模板引擎,是基于Mustache的扩展.模板引擎的都存在一个上下文环境,这是它的作用区间. 需求:基本使用 需要的库 <scr ...

  5. Java 内部类详解

    什么 定义在一个类内部的类,称为内部类(累不累),如下: public class A { private int c = 1; public class C { public void test() ...

  6. Linux 搭建Zookeeper集群

    1.使用root创建zookeeper用户:     useradd zookeeper:     passwd  zookeeper; 2.登录zookeeper用户,将下载的zookeeper-3 ...

  7. 用smarty来做简易留言系统,明细步骤简单操作

    留言信息是之前用php做过的一个例子,现在把它用smarty模板来做 大概是这样子 点击发布信息 然后填写内容,发送后会返回表格,写的内容都会出现在表格里 数据库的数据是这样的: 先建两个文件.php ...

  8. 你知道自己执行的是哪个jre吗?

    多个JRE 我在做<Java日志工具之java.util.logging.Logger>的DEMO时,修改java.util.logging.Logger的配置文件,怎么修改都不起作用,因 ...

  9. swift -- 基础

    swift -- 基础 1.常量和变量 常量: let 变量: var 2.声明常量和变量 常量的声明: let let  a = 1         //末尾可以不加分号,等号两边的空格必须对应(同 ...

  10. Spring注解问题,[action中注入service失败

    pring-mvc.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...