题意:给出n,求至少两个正整数,使得它们的最小公倍数为n,且这些整数的和最小 看的紫书--- 用唯一分解定理,n=(a1)^p1*(a2)^p2---*(ak)^pk,当每一个(ak)^pk作为一个单独的数的时候,和最小 然后就有三种情况 普通的,比如,2*3*3*5,sum=2+9+5=16 只有1个因数的,比如32=2^5,sum=32+1; 没有因数,自己本身是质数,sum=n+1: 因为分解的时候是找到根号n的,比如21,最后还会剩下7,所以sum=sum+n #include<iost…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1732 题意: 输入整数n(1≤n<2^31),求至少两个正整数,使得它们的最小公倍数为n,且这些整数的和最小.输出最小的和. 分析: 设唯一分解式n=(a1^p1)*(a2^p2)…,不难发现每个(ai^pi)作为一个单独的整数时最优.注意几个特殊情况:n=1时答案为1+1=…
Pairs Forming LCM Find the result of the following code: ; i <= n; i++ )        for( int j = i; j <= n; j++ )           if( lcm(i, j) == n ) res++; // lcm means least common multiple    return res;} A straight forward implementation of the code may…
http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1236 Description Find the result of the following code: long long pairs…
题目链接:https://cn.vjudge.net/problem/LightOJ-1236 题意 给一整数n,求有多少对a和b(a<=b),使lcm(a, b)=n 注意数据范围n<=10^14 思路 唯一分解定理 要注意的是条件a<=b,这就是说,在不要求大小关系的情况下 ans包括a<b,a>b和a==b的情形,最终答案就是(ans+1)/2 注意数据范围,求因数时使用1e7的素数即可,剩余的未被分解的数一定是大素数 首先求一下素数加速求因数,其次注意prime*pr…
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=109329#problem/B    全题在文末. 题意:在a,b中(a,b<=n)(1 ≤ n ≤ 1014),有多少组(a,b)  (a<b)满足lcm(a,b)==n; 先来看个知识点: 素因子分解:n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en for i in range(1,n): ei 从0取到ei的所有组合 必能包含所有n的因子. 现…
Pairs Forming LCM (LightOJ - 1236)[简单数论][质因数分解][算术基本定理](未完成) 标签: 入门讲座题解 数论 题目描述 Find the result of the following code: long long pairsFormLCM( int n ) { long long res = 0; for( int i = 1; i <= n; i++ ) for( int j = i; j <= n; j++ ) if( lcm(i, j) ==…
B - Pairs Forming LCM Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1236 Description Find the result of the following code: long long pairsFormLCM( int n ) {    long long res = 0;    for( in…
UVA.10791 Minimum Sum LCM (唯一分解定理) 题意分析 也是利用唯一分解定理,但是要注意,分解的时候要循环(sqrt(num+1))次,并要对最后的num结果进行判断. 代码总览 #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #define nmax 505 #define ll long long using namespace…
Find the result of the following code: long long pairsFormLCM( int n ) {    long long res = 0;    for( int i = 1; i <= n; i++ )        for( int j = i; j <= n; j++ )           if( lcm(i, j) == n ) res++; // lcm means least common multiple    return r…
题目: B - Pairs Forming LCM Time Limit:2000MS     Memory Limit:32768KB Description Find the result of the following code: long long pairsFormLCM( int n ) {long long res = 0;for( int i = 1; i <= n; i++ )for( int j = i; j <= n; j++ )if( lcm(i, j) == n )…
1236 - Pairs Forming LCM   Find the result of the following code: long long pairsFormLCM( int n ) {    long long res = 0;    for( int i = 1; i <= n; i++ )        for( int j = i; j <= n; j++ )           if( lcm(i, j) == n ) res++; // lcm means least…
转自:http://www.cnblogs.com/shentr/p/5285407.html http://acm.hust.edu.cn/vjudge/contest/view.action?cid=109329#problem/B 全题在文末. 题意:在a,b中(a,b<=n)( ≤ n ≤ 10^14),有多少组(a,b) (a<b)满足lcm(a,b)==n; 先来看个知识点: 素因子分解:n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en ,n):…
唯一分解定理是指任何正整数都可以分解为一些素数的幂之积,即任意正整数n=a1^p1*a2^p2*...*ai^pi:其中ai为任意素数,pi为任意整数. 题意是输入整数n,求至少2个整数,使得它们的最小公倍数为n,且这些整数的和最小,输出最小的和.由唯一分解定理可看出当每个ai^pi作为一个单独的整数时最优,只要注意你=1时的答案为2,n的因子只有一种时需要加个1以及n=2^31-1不要溢出即可写出程序.需注意的是应从2开始寻找质因子,因为2是最小的素数,由于习惯从1开始循环则是错误的. 代码如…
原题:https://vjudge.net/problem/UVA-10791 基本思路:1.借助唯一分解定理分解数据.2.求和输出 知识点:1.筛法得素数 2.唯一分解定理模板代码 3.数论分析-唯一分解定理的性质 唯一分解定理:该定理通过素数将任意一个大于2的n分解为 最小质数因子的幂 的乘积.这是一个数字简化的过程. 题目易错点在于要求得到的是 ‘n的多个因子的和’,且该多个因子的最小公倍数为n.是多个,而不是两个!!由此看来,其实如果把分解定理得到的每一个‘质数^指数’的形式看作一个整数…
A - (例题)整数分解 Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description Find the result of the following code: long long pairsFormLCM( int n ) {    long long res = 0;   …
题目链接:https://vjudge.net/problem/LightOJ-1236 1236 - Pairs Forming LCM    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Find the result of the following code: long long pairsFormLCM( int n ) {    long long res = 0;    for(…
题目描述 Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫 Hankson.现 在,刚刚放学回家的 Hankson 正在思考一个有趣的问题. 今天在课堂上,老师讲解了如何求两个正整数 c1 和 c2 的最大公约数和最小公倍数.现 在 Hankson 认为自己已经熟练地掌握了这些知识,他开始思考一个“求公约数”和“求公 倍数”之类问题的“逆问题”,这个问题是这样的:已知正整数 a0,a1,b0,b1,设某未知正整 数 x 满足: 1. x 和 a0 的最大公约…
GCD and LCM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 3409    Accepted Submission(s): 1503 Problem Description Given two positive integers G and L, could you tell me how many solutions of…
题意:求有多少对数对(i,j)满足lcm(i,j) = n,1<=i<=j, 1<=n<=1e14. 分析:根据整数的唯一分解定理,n可以分解为(p1^e1)*(p2^e2)*(p3^e3)*...*(pn^en).其中pi是每个不同的素因子. 同样可将 i 和 j 分解为(a1^c1)*(a2^c2)^(a3^c3)...(an^cn) 和 (b1^d1)*(b2^d2)*(b3^d3)*...(bn^dn). 因为lcm(i,j) = n.所以对任意 i,都有max(ci,di…
唯一分解定理: Uva10791 题意: 输入整数n,要求至少两个正整数,使得他们的最小公倍数为n,且这些整数的和最小 解法: 首先假设我们知道了一系列数字a1,a2,a3……an,他们的LCM是n,那么什么时候他们是最优解呢,当他们两两互质的时候 为了方便我们以两个数来说明问题. a和b的LCM是n,GCD是m,那么n=a/m*b , 它们的和就是sum=a+b; 如果m不为1(即a和b不互质),那么我们为什么不优化一下,将a变为a=a/m呢?,改变后a和b的LCM依然是n,但是他们的和显然减…
题目链接 Sumdiv Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 25841   Accepted: 6382 Description Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S…
题目链接:http://poj.org/problem?id=2773 Happy 2006 Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12942   Accepted: 4557 Description Two positive integers are said to be relatively prime to each other if the Great Common Divisor (GCD) is 1.…
题意:给出a,b,问有多少种长方形满足面积为a,最短边>=b? 首先简单讲一下唯一分解定理. 唯一分解定理:任何一个自然数N,都可以满足:,pi是质数. 且N的正因子个数为(1+a1)*(1+a2)*(1+a3)*.......*(1+an). 看了网络上很多人写的题解,普遍的做法是先找出N的所有正因子n,(n/2)就是在不考虑最短边>=b时所有存在的长方形,现在考虑最短边>=b,只需要减去所有能整除a且小于b的因子即可. 具体写法: 1.先预处理素数 2.用唯一分解定理求出N的所有因子…
题目链接:http://codeforces.com/contest/1228/problem/C 题解:给定一个函数f,g,题目有描述其中的表达式含义和两者之间的关系. 然后计算: 首先把给定的x用唯一分解定理分解出素因子 因为在1-n中,n/p(素因子)的值就是其1-n中有多少个数能整除p,n/p^2就是有多少个数能被p^2整除,所以做一次循环,每次n=n/p,直到n为0,sum记录每次n除以p的个数,就是1-n中能整除p的次方的数的幂指数之和了. 举个例子,45和3,n=45,p=3,第一…
You are given an array aa consisting of nn integers. Your task is to say the number of such positive integers xx such that xx divides eachnumber from the array. In other words, you have to find the number of common divisors of all elements in the arr…
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4053   Accepted: 1318 Description The binomial coefficient C(m,n) is defined as m! C(m,n) = -------- n!(m-n)! Given four natural numbers p, q…
uva10375 Choose and Divide(唯一分解定理) 题意: 已知C(m,n)=m! / (n!*(m-n!)),输入整数p,q,r,s(p>=q,r>=s,p,q,r,s<=10000), 计算C(p,q)/C(r,s).输出保证不超过10^8,保留5位小数. 分析: 本题时间上基本上没有太大的限制,可以暴力求解C(m,n); #include<cstdio> #include<cstring> #include<iostream>…
http://lightoj.com/volume_showproblem.php?problem=1341 题目大意: 给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. 什么叫唯一分解定理:算术基本定理可表述为:任何一个大于1的自然数 N,如果N不为质数,那么N可以唯一分解成有限个质数的乘积N=P1a1P2a2P3a3......Pnan,这里P1<P2<P3......<Pn均为质数,其中指数ai是正整数.这样的分解称为 N 的标准分解式 我们求出n的因…
题意:求C(p,q)/C(r,s),4个数均小于10000,答案不大于10^8 思路:根据答案的范围猜测,不需要使用高精度.根据唯一分解定理,每一个数都可以分解成若干素数相乘.先求出10000以内的所有素数,用a数组表示唯一分解式中个素数的指数,求出每个分子部分的素因子,并且相应的素数的指数加一.分母则减一.最后求解唯一分解式的值. #include<stdio.h> #include<string.h> #include<math.h> ; int pr[N],p[N…