oilover的AC之路

赛码杯大赛的水题。。。

直接按照题意搞,,最后判断一下是否合法。。也就是所有的询问是否被满足。。。

GCDTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 240Accepted Submission(s): 131

Problem Description

In mathematics, the greatest common divisor (gcd) of two or more integers, when at least one of them is not zero, is the largest positive integer that divides the numbers without a remainder. For example, the GCD of 8 and 12 is 4.—WikipediaBrotherK and Ery like playing mathematic games. Today, they are playing a game with GCD.BrotherK has an array, each element is a integer in [1, 10^9]. Ery hasquestions, the i-th question is to calculateGCD(), and BrotherK will tell her the answer.BrotherK feels tired after he has answeredquestions, so Ery can only play with herself, but she don’t know any elements in array. Fortunately, Ery remembered all her questions and BrotherK’s answer, now she wants to recovery the array.

Input

The first line contains a single integer, indicating the number of test cases.Each test case begins with two integers, indicating the number of array, and the number of Ery’s questions. Followinglines, each line contains three integers, describing the question and BrotherK’s answer.is about 10

Output

For each test, print one line.If Ery can’t find any array satisfy all her question and BrotherK’s answer, print "Stupid BrotherK!" (without quotation marks). Otherwise, printinteger, i-th integer is.If there are many solutions, you should print the one with minimal sum of elements. If there are still many solutions, print any of them.

Sample Input

22 21 2 11 2 22 11 2 2

Sample Output

Stupid BrotherK!2 2

Source

赛码"BestCoder"杯中国大学生程序设计冠军赛

#include <bits/stdc++.h>using namespace std;#define prt(k) cerr<<#k" = "<<k<<endl#define pb push_back#define MP make_pair#define fi first#define se second#define ALL(v) (v).begin(), (v).end()#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)#define SZ(X) ((int)(v).size())#define For(i,l,r) for (int i = l; i <= r; ++i)#define Cor(i,l,r) for (int i = l; i >= r; –i)#define Fill(a,b) memset(a,b,sizeof(a))#define READ freopen("a.in","r",stdin);freopen("a.out","w",stdout)void read(string t){freopen((t+".in").c_str(),"r",stdin);freopen((t+".out").c_str(),"w",stdout);}const int inf = 0x3f3f3f3f;typedef long long ll;typedef vector<int> VI;typedef vector<VI> VII;typedef pair<int,int> pii;template <class T>void Max(T &a, T b) { a=max(a, b); }const int N = 2333;ll a[N];ll gcd(ll a, ll b){return b==0 ? a : gcd(b, a%b);}ll lcm(ll a, ll b){return a / gcd(a, b) * b;}int n, Q;struct P{int l, r, a;} q[N];int main(){int re,ca=1; cin>>re;while (re–) {cin>>n>>Q;for (int i=1;i<=n;i++) a[i] = 1;for (int i=0;i<Q;i++) {scanf("%d%d%d", &q[i].l, &q[i].r, &q[i].a);int l=q[i].l, r = q[i].r;for (int j = l; j <= r; j++) {a[j] = lcm(a[j], q[i].a);}}bool ok = true;for (int i=0;i<Q;i++) {int l=q[i].l, r = q[i].r;ll g = a[l];for (int j=l+1;j<=r;j++) g = gcd(g, a[j]);if (g != q[i].a) ok = false;}if (!ok) {puts("Stupid BrotherK!");continue;}for (int i=1;i<=n;i++) {printf("%I64d%c", a[i], i<n ? ' ' : 10);}}return 0;}

阳光总在风雨后。只有坚强的忍耐顽强的奋斗,

oilover的AC之路

相关文章:

你感兴趣的文章:

标签云: