Describtion

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.—Wikipedia

BrotherK and Ery like playing mathematic games. Today, they are playing a game with GCD.

BrotherK has an array A with N elements: A1 ~ AN, each element is a integer in [1, 10^9]. Ery has Q questions, the i-th question is to calculate

GCD(ALi, ALi+1, ALi+2, …, ARi), and BrotherK will tell her the answer.

BrotherK feels tired after he has answered Q questions, so Ery can only play with herself, but she don’t know any elements in array A. Fortunately, Ery remembered all her questions and BrotherK’s answer, now she wants to recovery the array A.

Input

The first line contains a single integer T, indicating the number of test cases.

Each test case begins with two integers N, Q, indicating the number of array A, and the number of Ery’s questions. Following Q lines, each line contains three integers Li, Ri and Ansi, describing the question and BrotherK’s answer.

T is about 10

2 ≤ N Q ≤ 1000

1 ≤ Li < Ri ≤ N

1 ≤ Ansi ≤ 109

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, print N integer, i-th integer is Ai.

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

2

2 2

1 2 1

1 2 2

2 1

1 2 2

Sample Output

Stupid BrotherK!

2 2

由于区间长度只有1000,所以暴力枚举,完事了,最后在检查一编完事。

#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
long long n, q; long long num[N], l[N], r[N], s[N]; long long gcd(long long a, long long b)
{
if (b == 0)
{
return a;
}
else
{
return gcd(b, a % b);
}
} int main()
{
int t;
scanf("%d", &t);
while (t--)
{
cin >> n >> q;
for (int i = 0; i < N; ++i)
{
num[i] = 1;
}
for (int i = 0; i < q; ++i)
{
cin >> l[i] >> r[i] >> s[i];
for (int j = l[i]; j <= r[i]; ++j)
{
num[j] = (num[j] * s[i]) / gcd(num[j], s[i]);
}
}
bool flag = true;
for (int i = 0; i < q; i++)
{
long long ans = num[l[i]];
for (int j = l[i] + 1; j <= r[i]; j++)
{
ans = gcd(ans, num[j]);
}
if (ans != s[i])
{
flag = false;
break;
}
}
if (flag)
{
for (int i = 1; i <n; i++)
{
cout << num[i]<<" ";
}
cout<<num[n]<<endl;
}
else
{
printf("Stupid BrotherK!\n");
}
}
return 0;
}

数学--数论--HDU 5223 - GCD的更多相关文章

  1. 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)

    先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...

  2. 数学--数论--HDU 5382 GCD?LCM?(详细推导,不懂打我)

    Describtion First we define: (1) lcm(a,b), the least common multiple of two integers a and b, is the ...

  3. 数学--数论--HDU 5019 revenge of GCD

    Revenge of GCD Problem Description In mathematics, the greatest common divisor (gcd), also known as ...

  4. 数学--数论--HDU 1792 A New Change Problem (GCD+打表找规律)

    Problem Description Now given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can ...

  5. 数学--数论--HDU 2582 F(N) 暴力打表找规律

    This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gc ...

  6. HDU 5223 GCD

    题意:给出一列数a,给出m个区间,再给出每个区间的最小公倍数 还原这列数 因为数组中的每个数至少都为1,而且一定是这个区间的最小公约数ans[i]的倍数,求出它与ans[i]的最小公倍数,如果大于1e ...

  7. 数学--数论--HDU - 6395 Let us define a sequence as below 分段矩阵快速幂

    Your job is simple, for each task, you should output Fn module 109+7. Input The first line has only ...

  8. 数学--数论--HDU - 6322 打表找规律

    In number theory, Euler's totient function φ(n) counts the positive integers up to a given integer n ...

  9. 数学--数论--HDU 1098 Ignatius's puzzle (费马小定理+打表)

    Ignatius's puzzle Problem Description Ignatius is poor at math,he falls across a puzzle problem,so h ...

随机推荐

  1. 原生js,jquery通过ajax获得后台json数据动态新增页面元素

    一.原生js通过ajax获取json数据 因为IE浏览器对ajax对象的创建和其他浏览器不同,为了兼容全部浏览器,我用下面的代码: function createXMLHttpRequest(){ t ...

  2. pip 命令参数以及如何配置国内镜像源

    文章更新于:2020-04-05 注:如果 pip 命令不可以用,参见:python pip命令不能用 文章目录 一.参数详解 1.命令列表 2.通用参数列表 二.实际应用 1.常用命令 2.`pip ...

  3. leetcode 746. Min Cost Climbing Stairs(easy understanding dp solution)

    leetcode 746. Min Cost Climbing Stairs(easy understanding dp solution) On a staircase, the i-th step ...

  4. javascript的数据类型(基本和复杂)

    一.基本数据类型 string number boolean  二.复杂数据类型 Array Date object RegExp Sting Number Boolean 核心:Object fun ...

  5. 机器学习常见面试题—支持向量机SVM

    前言 总结了2017年找实习时,在头条.腾讯.小米.搜狐.阿里等公司常见的机器学习面试题. 支持向量机SVM 关于min和max交换位置满足的 d* <= p* 的条件并不是KKT条件 Ans: ...

  6. Python - Python的基础知识结构,学习方法、难点和重点

    [原创]转载请注明作者Johnthegreat和本文链接. 相信大家都知道,Python很容易学,有编程基础的人,最多两个星期就可以很愉快的撸Python的代码了,那么具体涉及的知识有哪些,下面为大家 ...

  7. sqli-labs通关教程----41~50关

    第四十关 与前几关一样,闭合变成') 插入数据 ?id=1') ;insert into users(id,username,password) values('17','aaa','bbb'); % ...

  8. 2020-3 网络对抗技术 20175120 exp5 信息搜集与漏洞扫描

    目录 实践目标 实践内容 各种搜索技巧的应用 搜索特定类型的文件Google Hacking 搜索网站目录结构 DNS IP注册信息的查询 网络侦查 基本的扫描技术:主机发现.端口扫描.OS及服务版本 ...

  9. [linux][nginx] 常用

    原文链接http://www.cnblogs.com/codingcloud/p/5095066.html 启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root ...

  10. 模糊字符串匹配:FuzzyWuzzy

    FuzzyWuzzy 模糊字符串匹配,它使用Levenshtein Distance来计算简单易用的包中序列之间的差异. 前置条件 Python 2.7 or higher difflib pytho ...