题意:给出一列数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. bzoj4519: [Cqoi2016]不同的最小割(分治最小割)

    4519: [Cqoi2016]不同的最小割 题目:传送门 题解: 同BZOJ 2229 基本一样的题目啊,就最后用set记录一下就ok 代码: #include<cstdio> #inc ...

  2. Linux下iscsi的使用

    查看是否已安装了iscsi-initiator:  [root@test\ ~]# rpm -qa |grep iscsi iscsi-initiator-utils-6.2.0.868-0.18.e ...

  3. [JZOJ 5906] [NOIP2018模拟10.15] 传送门 解题报告(树形DP)

    题目链接: https://jzoj.net/senior/#contest/show/2528/2 题目: 8102年,Normalgod在GLaDOS的帮助下,研制出了传送枪.但GLaDOS想把传 ...

  4. 132.try throw catch介绍

    #include <iostream> using namespace std; //try尝试执行,抛出throw,throw之后语句不再执行 //catch处理throw的异常 voi ...

  5. JavaScript中Math常用方法

    title: JavaScript中Math常用方法 toc: false date: 2018-10-13 12:19:31 Math.E --2.718281828459045,算数常量e Mat ...

  6. python网页问题

    #django-admin不是个命令 添加环境变量 D:\Python36\Scripts #localhost加载失败 命令行 python manage.py runserver 0.0.0.0: ...

  7. sql server2008怎么给一张表加一个用户

    有时候我们要对数据库进行权限管理,防止有人误操作或者窃取数据,那么小编这篇文章就是实现这个的操作过程. 百度经验:jingyan.baidu.com 工具/原料   sql server2008数据库 ...

  8. NEC芯片特别说明

    NEC芯片注意点: 1.堆栈和RAM共用,而且是程序中自定义堆栈的空间,堆栈是向下递减堆栈. 2.中断中标志位的清除可以不用手动清除,在中断服务程序中运行任何一条指令后自动清除. 3.中断服务程序有且 ...

  9. HDU 1950 Bridging signals【最长上升序列】

    解题思路:题目给出的描述就是一种求最长上升子序列的方法 将该列数an与其按升序排好序后的an'求出最长公共子序列就是最长上升子序列 但是这道题用这种方法是会超时的,用滚动数组优化也超时, 下面是网上找 ...

  10. 视图层 view

    视图层是 Django 处理请求的核心代码层,我们大多数 Python 代码都集中在这一层面.它对外接收用户请求,对内调度模型层和模版层,统合数据库和前端,最后根据业务逻辑,将处理好的数据,与前端结合 ...