LCM Cardinality

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit Status

Description

 

Problem F
LCM Cardinality
Input: Standard Input

Output: Standard Output

Time Limit: 2 Seconds

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 LCMof (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 theLCM 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                             Output for Sample Input

2 
12 
24 
101101291 
0 

2 2

12 8

24 11

101101291 5

 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
int gcd(int x,int y)
{
if(y==)return x;
return gcd(y,x%y);
}
int lcm(int x,int y)
{
return x/gcd(x,y)*y;
}
long long c[];
int main()
{
int n,nu,i,j,size,ans;
while(scanf("%d",&n),n)
{
ans=nu=;
size=sqrt(n+0.5);
for(i=; i<=size; i++)
{
if(n%i==)
{
c[nu++]=i;
if(i*i!=n)
c[nu++]=n/i;
}
}
for(i=; i<nu; i++)
{
for(j=i; j<nu; j++)
if(lcm(c[i],c[j])==n)ans++;
}
cout<<n<<" "<<ans<<endl;
}
}

LCM Cardinality 暴力的更多相关文章

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

  2. UVA 10892 - LCM Cardinality

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

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

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

  4. Uva 10892 LCM Cardinality (数论/暴力)

    题意:给出数n,求有多少组A,B的最小公约数为n; 思路:3000ms,直接暴力寻找,找到所有能把n整除的数 pi, 枚举所有pi 代码: #include <iostream> #inc ...

  5. LCM Cardinality

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=31675#problem/E 暴力 // File Name: uva10892.cpp ...

  6. UVa 10892 (GCD) LCM Cardinality

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

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

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

  8. LCM Cardinality UVA - 10892(算术基本定理)

    这题就是 LightOJ - 1236 解析去看这个把https://www.cnblogs.com/WTSRUVF/p/9185140.html 贴代码了: #include <iostrea ...

  9. 青岛网络赛J-Press the button【暴力】

    Press the Button Time Limit: 1 Second      Memory Limit: 131072 KB BaoBao and DreamGrid are playing ...

随机推荐

  1. login shell与non-login shell的区别

    Bash应该是我们每天日常工作接触最多的东西了,就像我们最忠实的朋友,我们有必要了解一下这位朋友的“习性”. Bash有几种不同的运行模式,login shell与non-login shell,in ...

  2. 常用Linux操作指令

    -------------------------------Linux目录------------------------------- /:根目录,一般根目录下只存放目录,在Linux下有且只有一 ...

  3. 第2阶段——编写uboot之编译测试以及改进(3)

    编译测试: 1.将写好的uboot复制到linux下面 2.make编译,然后将错误的地方修改,生成boot.bin (编译出错的解决方案:http://www.cnblogs.com/lifexy/ ...

  4. 个人作业2-英语学习案例app分析

    第一部分 调研, 评测 (软件的bug,功能评测,黑箱测试, 第8章 用户调研, 12 章 软件的用户体验) 下载并使用,描述最简单直观的个人第一次上手体验. ①个人感觉还不错,词典的首页页面挺好看的 ...

  5. Swing-JTable检测单元格数据变更事件

    在JTable的初级教程中往往会提到,使用TableModel的 addTableModelListener方法可以监听单元格数据的变更,在其事件处理函,数tableChanged中,可以通过e.ge ...

  6. 201521123017 《Java程序设计》第6周学习总结

    1. 本周学习总结 <> 2. 书面作业 Q1.clone方法 1.1 Object对象中的clone方法是被protected修饰,在自定义的类中覆盖clone方法时需要注意什么? 1. ...

  7. 201521123079 《Java程序设计》第1周学习总结

    1. 本周学习总结 了解学习了JAVA的开发环境的基础内容以及JDK,JRE等,学会用eclipse编写简单的代码 2. 书面作业 Q1.为什么java程序可以跨平台运行?执行java程序的步骤是什么 ...

  8. Java课程设计——GUI密码生成器团队博客

    1.团队名称.团队成员介绍(需要有照片) 1.1团队名称 小黄人 1.2团队成员介绍 吴玲:组长,现任院就业会策划部副部长 郭琪容:组员,现任院硬件协会会长 2. 项目git地址 吴 玲 郭琪容 3. ...

  9. 201521123045java课程设计---定时器

    #课程设计--定时器(201521123045 郑子熙) 1.团队课程设计博客链接 http://www.cnblogs.com/chendajia/p/7065730.html 2.个人负责模块或任 ...

  10. 201521123014 《Java程序设计》第11周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 Q1 互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) 1.1 除了使用sync ...