fzu 1753 质因数的应用

Another Easy Problem

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

xtt最近学习了高斯消元法解方程组,现在他的问题来了,如果是以下的方程,那么应该如何解呢?

C(n1,m1)==0 (mod M)

C(n2,m2)==0 (mod M)

C(n3,m3)==0 (mod M)

................

C(nk,mk)==0 (mod M)

xtt希望你告诉他满足条件的最大的M

其中C(i,j)表示组合数,例如C(5,2)=10,C(4,2)=6...

Input

输入数据包括多组,每组数据的第一行是一个正整数T(1<=T<=150)表示接下来描述的T个方程

接下来T行,每行包括2个正整数ni,mi (1<=mi<=ni<=100000)

Output

输出一行答案,表示满足方程组的最大M。

Sample Input

3
100 1
50 1
60 1

Sample Output

10
 1 #include <iostream>
 2 #include <cmath>
 3 #include <cstdio>
 4 #include <cstring>
 5 using namespace std;
 6
 7 typedef __int64 LL;
 8 const int maxn=1e5+5;
 9 int prime[10000],num,n[200],m[200];
10 bool flag[maxn];
11
12 void init()
13 {
14     memset(flag,true,sizeof(flag));
15     int i,j;num=0;
16     for(i=2;i<maxn;i++)
17     {
18         if(flag[i]) prime[num++]=i;
19         for(j=0;j<num&&i*prime[j]<maxn;j++)
20         {
21             flag[i*prime[j]]=false;
22             if(i%prime[j]==0) break;
23         }
24     }
25 }
26
27 int factor(int a,int b)
28 {
29     int sum=0;
30     while(b)
31     {
32         sum+=b/a;
33         b/=a;
34     }
35     return sum;
36 }
37
38 int getfactor(int i,int j)
39 {
40     int sum=factor(prime[i],n[j]);
41     sum-=factor(prime[i],m[j]);
42     sum-=factor(prime[i],n[j]-m[j]);
43     return sum;
44 }
45
46 LL mypow(LL a,LL b)
47 {
48     LL ret=1;
49     while(b)
50     {
51         if(b&1) ret*=a;
52         a*=a;
53         b>>=1;
54     }
55     return ret;
56 }
57
58 LL solve(int n,int MAX)
59 {
60     LL ans=1;
61     for(int i=0;i<num&&prime[i]<=MAX;i++)
62     {
63         int min=10000,c;
64         for(int j=0;j<n;j++)
65         {
66             c=getfactor(i,j);
67             min=min<c?min:c;
68         }
69         ans*=mypow(prime[i],min);
70     }
71     return ans;
72 }
73
74 int main()
75 {
76     init();
77     int i,t,MIN;
78     while(~scanf("%d",&t))
79     {
80         MIN=1e9;
81         for(i=0;i<t;i++)
82         {
83             scanf("%d %d",n+i,m+i);
84             MIN=MIN<n[i]?MIN:n[i];
85         }
86         printf("%I64d\n",solve(t,MIN));
87     }
88     return 0;
89 }

fzu 1753 质因数的应用

时间: 2024-07-29 11:00:49

fzu 1753 质因数的应用的相关文章

fzu 1753 Another Easy Problem

本题题意为求 t (t<150) 个 c (n,m)  (1<=m<=n<=100000)的最大公因子: 本题的难点为优化.主要有两个优化重点.一是每次对单个素因子进行处理,优化每次的数组清零:二是对求阶乘素因子个数的优化 ei=[N/pi^1]+ [N/pi^2]+ …… + [N/pi^n]  其中[]为取整 ei 为数 N!中pi 因子的个数: #include <iostream>#include <cstring>#include <cmat

FZU 1753-Another Easy Problem(求多个组合数的最大公约数)

Another Easy Problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice FZU 1753 Appoint description:  xietutu  (2013-03-13)System Crawler  (2015-04-27) Description 小TT最近学习了高斯消元法解方程组,现在他的问题来了,如果是以下的方程,

【BZOJ2227】【ZJOI2011】看电影 [组合数学][质因数分解]

看电影 Time Limit: 10 Sec  Memory Limit: 259 MB[Submit][Status][Discuss] Description 到了难得的假期,小白班上组织大家去看电影.但由于假期里看电影的人太多,很难做到让全班看上同一场电影,最后大家在一个偏僻的小胡同里找到了一家电影院.但这家电影院分配座位的方式很特殊,具体方式如下: 1. 电影院的座位共有K个,并被标号为1…K,每个人买完票后会被随机指定一个座位,具体来说是从1…K中等可能的随机选取一个正整数,设其为L.

FZU 2150 Fire Game(点火游戏)

p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h2 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: left; font-family: 宋体; font-weight: bold; font-size: 18.0000pt } h3 {

FZU 1096 QS Network

QS Network Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on FZU. Original ID: 1096 64-bit integer IO format: %I64d      Java class name: Main In the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS.

分解质因数模板

/*==================================================*| 分解质因数,可能有些地方需要改为long long \*==================================================*/ const int MAXN=100010; int prm[MAXN+1]; bool is[MAXN+1]; int getprm(int n){ int i, j, k = 0; int s, e = (int)(sqrt

C语言之基本算法34—分解质因数(方法一)

//矩阵基础 /* ================================================================== 题目:输入一个正整数.将其分解为质因式,如:60=2*2*3*5:若本身是质数,则输出 如:307是一个质数! ================================================================== */ #include<stdio.h> void main() { int n,m,c,i,k,

java编程题 --分解质因数

package Solve; import java.util.Scanner; public class Solve { static Scanner scan = new Scanner(System.in); public static void main(String[] args) { System.out.println("请输入一个正整数:"); int num = scan.nextInt(); System.out.print(num + " = "

FZU 1759 欧拉函数 降幂公式

Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000). Input There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a singl