题目的思路还是很简单的,找出这些组合数中最大的公约数;

其中C(n,k)=n ! /k!/(n-k)!

所以枚举每个素因数,用(n!)的减去(k!)和(n-k)!的就行了...

最后取每组的最小值

 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std;
const int maxn=;
const int inf=0x3fffffff;
int prime[maxn],num;
bool isprime[maxn];
int cnt[maxn],lim;
typedef unsigned long long ll; void init()
{
for(int i=; i<maxn; i++)
if(!isprime[i])
{
prime[num++]=i;
for(int j=*i; j<maxn; j+=i)
isprime[j]=;
}
} void cal(int a,int b,int c)
{
int nn=-;
for(int i=; prime[i]<=lim; i++)
{
int t=,pre=a;
if(pre>=prime[i]) while(pre) t+=pre/prime[i],pre/=prime[i];
pre=b;
if(pre>=prime[i]) while(pre) t-=pre/prime[i],pre/=prime[i];
pre=c;
if(pre>=prime[i]) while(pre) t-=pre/prime[i],pre/=prime[i];
if(cnt[i]==-||cnt[i]>t) cnt[i]=t;
if(cnt[i]) nn=prime[i];
}
lim=nn;
}
ll pow1(ll a,int n)
{
ll ret=;
for(; n; n>>=,a=a*a)
if(n&) ret*=a;
return ret;
}
int main()
{
init();
int n,a[],b[];
while(scanf("%d",&n)==)
{
lim=inf;
for(int i=; i<n; i++)
{
scanf("%d %d",&a[i],&b[i]);
lim=min(lim,a[i]);
}
memset(cnt,-,sizeof(cnt));
for(int i=; i<n; i++)
cal(a[i],b[i],a[i]-b[i]);
ll ans=;
for(int i=; prime[i]<=lim; i++)
if(cnt[i]>) ans*=pow1(prime[i],cnt[i]);
printf("%I64u\n",ans);
}
return ;
}

FZU 1753的更多相关文章

  1. fzu 1753 Another Easy Problem

    本题题意为求 t (t<150) 个 c (n,m)  (1<=m<=n<=100000)的最大公因子: 本题的难点为优化.主要有两个优化重点.一是每次对单个素因子进行处理,优 ...

  2. fzu 1753 质因数的应用

    Another Easy Problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  3. CSU训练分类

    √√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 ...

  4. SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

    相信很多人进行数据存储时,会遇上如标题的异常错误. 其实也不算上一个错误. 当你的程序中有宣告一个字段的数据类型为DateTime时,但你又没有赋值给它,就进行存储时,它就会得到这样一个结果. 看看下 ...

  5. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  6. FZU 2137 奇异字符串 后缀树组+RMQ

    题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...

  7. FZU 1914 单调队列

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...

  8. ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】

     FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  9. [ACM训练] 算法初级 之 基本算法 之 枚举(POJ 1753+2965)

    先列出题目: 1.POJ 1753 POJ 1753  Flip Game:http://poj.org/problem?id=1753 Sample Input bwwb bbwb bwwb bww ...

随机推荐

  1. Linux 释放cached内存

    使用free -m 查看系统使用的内存情况: # free -m             total      used      free      shared      buffers     ...

  2. Java基础知识强化之IO流笔记38:字符流缓冲流之BufferedWriter / BufferedReader使用

    1. 字符流缓冲流: 字符流为了高效读写,也提供了对应的字符缓冲流. BufferedWriter:字符缓冲输出流 BufferedReader:字符缓冲输入流 2. BufferedWriter使用 ...

  3. windows下使用redis,Redis入门使用,Redis基础命令

    windows下使用redis,Redis入门使用,Redis基础命令 >>>>>>>>>>>>>>>> ...

  4. C# ADO.NET参数查询

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. (转)asp.net 高质量缩略图

    原文地址:http://www.cnblogs.com/Fooo/archive/2009/06/19/1506381.html using System.Drawing; ------------- ...

  6. SQLServe错误整理

    1. sql拒绝访问?提示SQL Serve不存在或访问被拒绝 (SQL Server does not exist or access denied.) (A) 1:你如果是独立上网的请把21端口打 ...

  7. 将分页功能从JSP页面中独立出来

    附带视频链接:http://www.tudou.com/programs/view/leaQ-YFl7W8/?bid=03&pid=2&resourceId=0_03_05_02

  8. Unity3D 之UGUI 文本框和编辑框

    这里来讲解一下unity3D自带的UI功能,自带的UI也叫UGUI功能非常的强大,比起NGUI,更加的灵活,让用户能够更加容易的去使用. 首先创建一个文本Text 然后是文本相对应的属性 这里的属性比 ...

  9. SQL Server 2008 TOP 新用途

    /***************创建测试表******************************/ IF NOT OBJECT_ID('[Demo_Top]') IS NULL DROP TAB ...

  10. 20160421javaweb之上传下载小案例---网盘

    一.建立数据库: CREATE TABLE IF NOT EXISTS `netdisk` ( `id` ) NOT NULL AUTO_INCREMENT, `uuidname` ) NOT NUL ...