标签:
题目链接:
Time Limit: 1000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
//#include <bits/stdc++.h> #include <vector> #include <iostream> #include <queue> #include <cmath> #include <map> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; #define Riep(n) for(int i=1;i<=n;i++) #define Riop(n) for(int i=0;i<n;i++) #define Rjep(n) for(int j=1;j<=n;j++) #define Rjop(n) for(int j=0;j<n;j++) #define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) { char CH; bool F=false; for(CH=getchar();CH<‘0‘||CH>‘9‘;F= CH==‘-‘,CH=getchar()); for(num=0;CH>=‘0‘&&CH<=‘9‘;num=num*10+CH-‘0‘,CH=getchar()); F && (num=-num); } int stk[70], tp; template<class T> inline void print(T p) { if(!p) { puts("0"); return; } while(p) stk[++ tp] = p%10, p/=10; while(tp) putchar(stk[tp--] + ‘0‘); putchar(‘\n‘); } const LL mod=1e9+7; const double PI=acos(-1.0); const LL inf=1e18; const int N=1e6+20; const int maxn=1005; const double eps=1e-10; int n,m; int a[15],b[15]; int gcd(int a,int b) { if(b==0)return a; return gcd(b,a%b); } int main() { int t; read(t); while(t--) { read(n);read(m); for(int i=1;i<=m;i++)read(a[i]); for(int i=1;i<=m;i++)read(b[i]); int lcm=1; for(int i=1;i<=m;i++) lcm=lcm/gcd(lcm,a[i])*a[i]; int flag=1; for(int i=1;i<=lcm&&i<=n;i++) { flag=1; for(int k=1;k<=m;k++) if(i%a[k]!=b[k])flag=0; if(flag) { printf("%d\n",(n-i)/lcm+1); break; } } if(!flag)printf("0\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zhangchengc919/p/5631036.html