Another easy problemTime
limit:MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64u SubmitStatusPracticeFzu 1753Appoint Description:Xietutu (2013-03-13)System Crawler (2015-04-27)
Description
The small TT recently learned the Gaussian elimination method to solve the equations, and now his problem comes, if it is the following equation, then how to solve it?
C (N1,M1) ==0 (mod M)
C (n2,m2) ==0 (mod M)
C (n3,m3) ==0 (mod M)
................
C (NK,MK) ==0 (mod M)
Little TT wants you to tell him to meet the conditions of the largest m
where C (I,J) represents the number of combinations, such as C (5,2) =10,c (4,2) =6 ...
Input
The input data consists of multiple groups, and the first row of each set of data is a positive integer t (1<=t<=150) representing the next described T equation
Next T line, each line consists of 2 positive integers ni,mi (1<=mi<=ni<=100000)
Output
Outputs one row of answers, representing the maximum m that satisfies the equation group.
Sample Input
3100 150 160 1
Sample Output
10
Idea: to multiply each combination into a mass factor, and then find out that the number of the mass factor in all combinations is the smallest, and then the number of all common mass factor is the least multiplied, the result is the greatest common divisor of the combined number.
Ps:wa several 10 times, the code re-knocked n times, the result of the output of printf changed to cout on the right, I really do not know why, it is the day the dog.
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include < iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include <stack> #include <map>using namespace std;typedef long long ll;const int inf=0x3f3f3f3f;const double pi= ACOs ( -1.0); #define Lson l,mid,rt<<1#define Rson mid+1,r,rt<<1|1int prime[100010]={2,3,5};int cnt[310][310]; int p[100010];int k=3;struct node{int n,m;} Q[210];void is_prime () {int i,j; int flag=0; int gad=2; for (i=7; i<100010; I+=gad) {flag=0; Gad=6-gad; for (j=0; prime[j]*prime[j]<=i; J + +) {if (i%prime[j]==0) {flag=1; Break }} if (!flag) {prime[k++]=i; }}}int get (int n,int cc)//This function asks for n! The number of CC quality factor {int cnt=0; while (n) {cnt+=n/cc; N=N/CC; } return CNT;} int get_res (int aa,int bb,int cc)//This function asks for the number of CC-Factor in C (n,m) {int sum=0; Sum=get (AA,CC)-get (BB,CC)-get (AA-BB,CC); return sum;} int main () {int T; int i,j; LL ans; int Minn; Is_prime (); while (~SCANF ("%d", &t)) {Ans=1; Minn=inf; for (i=0;i<t;i++) {scanf ("%d%d", &Q[I].N,&Q[I].M); Minn=min (MINN,Q[I].N),///greatest common divisor the largest n value is the smallest of all n of the} for (j=0;prime[j]<=minn;j++) {//traverse each prime factor, find the smallest P[j]=inf; for (i=0;i<t;i++) {int r=get_res (q[i].n,q[i].m,prime[j]); P[j]=min (R,p[j]); } for (i=0;i<p[j];i++) ans*=prime[j]; } cout<<ans<<endl; } return 0;}
Fzu 1753-another Easy problem (for greatest common divisor of multiple combinations)