http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1732

给定我们一个n, 要找到两个数的集合,使得这些书的最小公倍数(LCM)为n,由于有很多这样的集合,我们要选出总和最小的,而且也只要输出总和就行了

数的最大公倍数是怎么求的?  是每个质因数指数最大的那个相乘而来的。

通过最小公倍数的求法,我们可以看出最小公倍数取决于每个质因子在各个数中的最高次。

如果要总和最小,我们要把同一个质因数放到一个整数里面

因为a*b>a+b

比如12 = 3 * 2^2    a = 3, b = 2             a * b > a + b   即2*3 > 2 + 3

所以最终的结果是3 * 4 = 12,   此时和最小,为7

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <math.h>
using namespace std;
#pragma warning(disable:4996)
typedef long long LL;
const int INF = <<;
/* */
int main()
{
LL n, i, m, k = ;
LL ans;
while (scanf("%lld", &n), n)
{
int nn = n;
ans = ;
m = sqrt(n) + 0.5;
int cnt = ;
for (i = ; i <= m; ++i)
{
if (n%i == )
{
int t = ;
while (n%i == )
{
t *= i;
n /= i;
}
ans += t;
cnt++;
}
}
if (n > )
{
ans += n;
cnt++;
}
if (cnt == )//这是只有单独一个数的情况
ans += ;
else if (cnt == )//这是n为1的情况
ans += ;
printf("Case %lld: %lld\n", k++,ans);
}
return ;
}

uva10780 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1721

给定m 和 n

求最大的x  使得 n % m^x  ==0,

思路:将m分解质因数,相同的质因数合并, 那么可以得到  p1^a1 , p2^a2..pn^an ,   我们只要求出n!中质因数pi 是pi^ai的多少次幂, 然后最小的那个次幂就是答案

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <math.h>
using namespace std;
#pragma warning(disable:4996)
typedef long long LL;
const int INF = <<;
/* */
int a[ + ];
int main()
{
int t, n, m;
scanf("%d", &t);
for (int k = ; k <= t; ++k)
{
int ans = INF;
scanf("%d%d", &m, &n);
int limit = sqrt(m) + 0.5;
for (int i = ; i <= limit; ++i)
{
if (m%i == )
{
int cnt = ;
while (m%i == )
{
cnt++;
m /= i;
}
int tmp = ;
for (int j = ; j <= n; ++j)
{
int x = j;
while (x % i == )
{
x /= i;
tmp++;
}
}
ans = min(ans, tmp/cnt);
}
}
if (m > )
{
int tmp = ;
for (int j = ; j <= n; ++j)
{
int x = j;
while (x % m == )
{
x /= m;
tmp++;
}
}
ans = min(ans, tmp);
}
if (ans == || ans==INF)
printf("Case %d:\nImpossible to divide\n",k);
else
printf("Case %d:\n%d\n", k, ans);
}
return ;
}

uva10791 uva10780(分解质因数)的更多相关文章

  1. uva10780(分解质因数)

    可以直接用高精度来暴力求. 也可以不用高精度: 把m分解质因数,记录每个因数和它的次数.然后计算每个因数在n的阶乘里出现了多少次,再把这个次数除以它在m中的次数,就是可能的k值.取最小的k. #inc ...

  2. java分解质因数

      package test; import java.util.Scanner; public class Test19 { /** * 分析:对n进行分解质因数,应先找到一个最小的质数k * 最小 ...

  3. 程序设计入门——C语言 第6周编程练习 1 分解质因数(5分)

    1 分解质因数(5分) 题目内容: 每个非素数(合数)都可以写成几个素数(也可称为质数)相乘的形式,这几个素数就都叫做这个合数的质因数.比如,6可以被分解为2x3,而24可以被分解为2x2x2x3. ...

  4. 【python】将一个正整数分解质因数

    def reduceNum(n): '''题目:将一个正整数分解质因数.例如:输入90,打印出90=2*3*3*5''' print '{} = '.format(n), : print 'Pleas ...

  5. light oj 1236 分解质因数

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/H 题意:求满足1<=i<=j<=n ...

  6. 【基础数学】质数,约数,分解质因数,GCD,LCM

    1.质数: 质数(prime number)又称素数,有无限个.一个大于1的自然数,除了1和它本身外,不能整除以其他自然数(质数),换句话说就是该数除了1和它本身以外不再有其他的因数. 2.约数: 如 ...

  7. 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m

    给定两个数m,n,其中m是一个素数. 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m. 输入 第一行是一个整数s(0<s<=100),表示测试数据的组数 随后 ...

  8. cdoj 1246 每周一题 拆拆拆~ 分解质因数

    拆拆拆~ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1246 Descri ...

  9. hdu 5428 The Factor 分解质因数

    The Factor  Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/contest ...

随机推荐

  1. 让AllocateHwnd接受一般函数地址作参数(105篇博客)

    http://www.xuebuyuan.com/1889769.html Classes单元的AllocateHWnd函数是需要传入一个处理消息的类的方法的作为参数的,原型: function Al ...

  2. JavaScript + CSS3 实现的海报画廊特效

    原文:JavaScript + CSS3 实现的海报画廊特效 这是慕课网上<CSS3+JS 实现超炫的散列画廊特效>的源代码,我修改了一些 bug 和调优了一些细节,并把学习过程中并不了解 ...

  3. 【Demo 0006】iOS常用控件

    本章学习要点       1.  了解iOS中控件继承关系:       2.  掌握UIControl基础知识;       3.  掌握UIButton基本用法:       4.  掌握UILa ...

  4. thinkphp模版调用函数方法

    原文:thinkphp模版调用函数方法 {变量|函数1|函数2|函数3=参数1,参数2,参数3,###} ###为第4个参数,代表变量替换为第4个参数 举例: {$username|substr=0, ...

  5. 加速 lucene 的搜索速度 ImproveSearchingSpeed

    * Be sure you really need to speed things up. Many of the ideas here are simple to try, but others w ...

  6. 彻底卸载McAfee和Agent的方法

    1.控制面板中-添加或删除程序中-删除"McAfee VirusScan Enterprise"和"McAfee AntiSpyware Enterprise Modul ...

  7. Java 螺纹第三版 第一章Thread介绍、 第二章Thread创建和管理学习笔记

    第一章 Thread导论 为何要用Thread ? 非堵塞I/O      I/O多路技术      轮询(polling)      信号 警告(Alarm)和定时器(Timer) 独立的任务(Ta ...

  8. 移植ffmpeg到VC环境心得

    所有想学习ffmpeg的网友有福了,大名鼎鼎的ffmpeg,移植到Windows的VC6版本全部开源,编译环境为VC6+SP5+VCPP5.别忘记了顶贴哦. 移植ffmpeg到windows,主要的修 ...

  9. 获取CentOS软件源中的updates包

    之前在本地网络中建了一个CentOS软件源,挺好用的,可是发现有些软件还是装不上,因为系统安装盘中的包并不全,有些软件的依赖在updates源中,updates源在网上,怎么把其中的包拿到呢?一种方法 ...

  10. Merging a WPF application into a single EXE(WPF应用程序合并成单个Exe文件)

    I always dislike handing off little applications to people. Not because I can’t, but because of the ...