题意:给出一列数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. 编写shell脚本获取本机的网络地址。&#160; 比方:本机的ip地址是:192.168.100.2/255.255.255.0,那么它的网络地址是&#160;192.168.100.1/255.255.255.

    ubuntu@ubuntu:~$ vim getlocalip.sh #!/bin/bash #ifconfig | grep inet | awk '$2' | awk -F : '$2' IP=` ...

  2. python微框架Bottle(http)

    环境: win7系统 Python2.7 一 背景和概述 眼下项目中须要加入一个激活码功能,打算单独弄一个httpserver来写. 由于之前的游戏中已经有了一套完整的激活码生成工具和验证httpse ...

  3. MongoDB数据查询详解

    查询全部 ​ db.infos.find(); db.infos.find({"url":"www.baidu.com"}); id不要显示出来 db.info ...

  4. c语言运算符优先级与while循环案例

    sizeof可以获取数据类型的内存中的大小(字节) #include <stdio.h> #include <stdlib.h> // standared 标准 // inpu ...

  5. DB-MySQL:MySQL 函数

    ylbtech-DB-MySQL:MySQL 函数 1. MySQL 字符串函数返回顶部 1. MySQL 字符串函数 函数 描述 实例 ASCII(s) 返回字符串 s 的第一个字符的 ASCII ...

  6. [jzoj 6087] [GDOI2019模拟2019.3.26] 获取名额 解题报告 (泰勒展开+RMQ+精度)

    题目链接: https://jzoj.net/senior/#main/show/6087 题目: 题解: 只需要统计$\prod_{i=l}^r (1-\frac{a_i}{x})$ =$exp(\ ...

  7. TYVJ1415 差分约束

    思路: i–>i+1连一条边权为0的边 i–>i-1连一条边权为-1的边 start-1 ->end 连一条边权为w的边 求0->n的最长路即可 //By SiriusRen ...

  8. @JsonIgnore忽略属性,返回的json中不包含字段

    @JsonIgnore的使用: 实体类中加@JsonIgnore注解 package com.baidu.entity; import com.fasterxml.jackson.annotation ...

  9. 滚动监听 after选择器

    一.如何实现滚动到一定位置将内容固定在页面顶部 window.onscroll=function(){ //滚动的距离,距离顶部的距离 var topScroll =document.body.scr ...

  10. 学习参考《Flask Web开发:基于Python的Web应用开发实战(第2版)》中文PDF+源代码

    在学习python Web开发时,我们会选择使用Django.flask等框架. 在学习flask时,推荐学习看看<Flask Web开发:基于Python的Web应用开发实战(第2版)> ...