题意:给出一列数a,给出m个区间,再给出每个区间的最小公倍数 还原这列数

因为数组中的每个数至少都为1,而且一定是这个区间的最小公约数ans[i]的倍数,求出它与ans[i]的最小公倍数,如果大于1e9(题目中给的范围,一定不能够还原)

最后按照这样算出每一个a[i]后,再检查一遍这m个区间的算出来的最小公约数是否和给出的一致

学习的dzy4939414644的代码

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i) typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=;
int n,m; struct node{
int l,r,x;
} ans[maxn]; int a[maxn]; LL gcd(LL a,LL b){
return (!b)? a:gcd(b,a%b);
} LL lcm(LL a,LL b){
return a/gcd(a,b)*b;
} void solve(){
for(int i=;i<=n;i++) a[i]=; for(int i=;i<=m;i++){
for(int j=ans[i].l;j<=ans[i].r;j++){
a[j]=lcm(a[j],ans[i].x);
if(a[j]>){
printf("Stupid BrotherK!\n");
return;
}
}
} for(int i=;i<=m;i++){
LL cur=;
for(int j=ans[i].l;j<=ans[i].r;j++){
cur=gcd(a[j],cur);
}
if(cur!=ans[i].x){
printf("Stupid BrotherK!\n");
return;
}
} printf("%d",a[]);
for(int i=;i<=n;i++) printf(" %d",a[i]);
printf("\n");
} int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d %d",&n,&m);
for(int i=;i<=m;i++) scanf("%d %d %d",&ans[i].l,&ans[i].r,&ans[i].x); solve();
}
return ;
}

HDU 5223 GCD的更多相关文章

  1. 数学--数论--HDU 5223 - GCD

    Describtion In mathematics, the greatest common divisor (gcd) of two or more integers, when at least ...

  2. HDU 5726 GCD 区间GCD=k的个数

    GCD Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  3. HDU 5902 GCD is Funny 数学

    GCD is Funny 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5902 Description Alex has invented a ne ...

  4. HDU 1695 GCD (欧拉函数+容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. HDU 1695 GCD 容斥

    GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1695 Description Given 5 integers: a, b, c, d, k ...

  6. hdu 4497 GCD and LCM 数学

    GCD and LCM Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4 ...

  7. HDU 4675 GCD of Sequence(容斥)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4675 题意:给出n,m,K,一个长度为n的数列A(1<=A[i]<=m).对于d(1< ...

  8. HDU 5726 GCD (RMQ + 二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5726 给你n个数,q个询问,每个询问问你有多少对l r的gcd(a[l] , ... , a[r]) ...

  9. HDU 5726 GCD(DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5726 [题目大意] 给出数列An,对于询问的区间[L,R],求出区间内数的GCD值,并且求出GCD ...

随机推荐

  1. Linux Screen命令使程序远离断网影响

    linux中强大的screen命令2008-12-02 21:53今天发现了一个“宝贝”,就是Linux的screen命令,对于远程登录来说,不仅提供了类似于nohup的功能,而且提供了我非常喜欢的“ ...

  2. Django(part4)

    一个简单的form表单: #polls/templates/polls/detail.html<h1>{{ question.question_text }}</h1> {% ...

  3. hiho1560 - 矩阵快速幂

    题目链接 坑死了,以为是K进制数,每一位可以是0-K之间的,其实是十进制,每一位最高为9,一直wa在这....... ----------------------------------------- ...

  4. Mysql语法:navicat for mysql 添加注释

    在 navicat 中有三种注释的书写方式: 以 # 开头的字符串,可以多个 # 连续以 – 开头的字符串,注意:只能是 – ,而且 – 后面需要加一个半角空格以 /* */ 包围的字符串,类似于 J ...

  5. HDU 2852 KiKi's K-Number【 树状数组 二分 】

    题意:给出m个操作,0:是增加一个数,add(x,1)1:是删除一个指定的数,这个是看sum(x) - sum(x-1)是否为0,为0的话则不存在,不为0的话,则add(x,-1)2:是查询比x大的数 ...

  6. swift where 的作用

    条件限定: 类型限定: 结构化查询模式. 用于结构体.记录字段.

  7. 【CS-4476-project 6】Deep Learning

    AlexNet / VGG-F network visualized by mNeuron. Project 6: Deep LearningIntroduction to Computer Visi ...

  8. SNMP学习

    http://blog.sina.com.cn/s/blog_4502d59c0101fcy2.html 简单网络管理协议(SNMP)是TCP/IP协议簇的一个应用层协议.在1988年被制定,并被In ...

  9. 怎样在windows7上使用snmp命令

    原文地址:http://wenboxz.com/archives/window7-use-snmp-command.html/

  10. android仿最新版本号微信相冊--附源代码

    更改排版为 markdown: http://blog.csdn.net/self_study/article/details/69397859