首页 > 其他分享 >Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 数学

Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 数学

时间:2023-04-24 22:37:00浏览次数:39  
标签:integers int ll Codeforces long Dreamoon 272 include define


Dreamoon likes to play with sets, integers and . is defined as the largest positive integer that divides both a and b.

Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, .

Given k and n, Dreamoon wants to make up n sets of rank k using integers from 1 to m such that no integer is used in two different sets (of course you can leave some integers without use). Calculate the minimum m that makes it possible and print one possible solution.

Input
The single line of the input contains two space separated integers n, k (1 ≤ n ≤ 10 000, 1 ≤ k ≤ 100).

Output
On the first line print a single integer — the minimal possible m.

On each of the next n lines print four space separated integers representing the i-th set.

Neither the order of the sets nor the order of integers within a set is important. If there are multiple possible solutions with minimal m, print any one of them.

Examples
inputCopy
1 1
outputCopy
5
1 2 3 5
inputCopy
2 2
outputCopy
22
2 4 6 22
14 18 10 16
Note
For the first example it’s easy to see that set {1, 2, 3, 4} isn’t a valid set of rank 1 since .

给定N个集合,每个集合里面的数的 gcd ==k ,且每个数只可以属于一个集合,问最大的数最小应该是多少?

找一下规律:1,2,3,5;7,8,9,11;13,14,15,17…….,以6 为一个周期,这些都是满足互质的,那么gcd==k ,也就是*k即可,

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
#include<bitset>
#include<ctime>

typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 200005
#define ms(x) memset(x,0,sizeof(x))
#define Inf 0x7fffffff
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;
#define pi acos(-1.0)
#define pii pair<int,int>
#define pll pair<ll,ll>



ll quickpow(ll a, ll b) {
    ll ans = 1;
    while (b > 0) {
        if (b % 2)ans = ans * a;
        b = b / 2;
        a = a * a;
    }
    return ans;
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}


int main()
{
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int a = 1, b = 2, c = 3, d = 5;
    cout << k * (d + 6 * (n - 1)) << endl;
    for (int i = 0; i < n; i++) {
        cout << a*k << ' ' << b*k << ' ' << c*k << ' ' << d*k << endl;
        a += 6;
        b += 6;
        c += 6;
        d += 6;
    }
    return 0;
}


标签:integers,int,ll,Codeforces,long,Dreamoon,272,include,define
From: https://blog.51cto.com/u_15657999/6221936

相关文章

  • Codeforces Round #308 (Div. 2) E. Vanya and Brackets
    Vanyaisdoinghismathshomework.Hehasanexpressionofform,wherex1, x2, …, xnaredigitsfrom1to9,andsignrepresentseitheraplus‘+’orthemultiplicationsign‘*’.Vanyaneedstoaddonepairofbracketsinthisexpressionsothattoma......
  • Educational Codeforces Round 147
    A题意思路有前导零结果直接为0,出现在第一位的?贡献为9,其他地方的?贡献为10。代码#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;chars[10];intmain(){intT;scanf("%d",&T);while(T--){scanf("%s",s);......
  • Educational Codeforces Round 147 (Rated for Div. 2)
    题目链接B核心思路真的需要加强了,看到这个最大值和最小值我们其实也需要往对应的最大值和最小值的相关操作去想,不如前缀最小值/前缀最大值或者是后缀最小值/后缀最大值。这里一个比较直接的想法就是想找到不同的地方,然后看不可以扩展。那么怎么看是否可以扩展呢,如果是左边的话......
  • Educational Codeforces Round 127 (Rated for Div. 2)
    题目链接D核心思路首先挖掘下操作的性质吧:x>1&&x+3<10:1xx+1x+2x+310我们可以发现这样子好像对于我们的结果是没有影响的,答案还是9.所以这个性质就挖掘出来了啊,只要我们把一段连续的插入到对应的区间里面就好了。也就是只要这个区间的左端点小于插入连续的数的最小值,......
  • cuda编程 转载https://zhuanlan.zhihu.com/p/592721411
     4.相关概念和术语在CUDA编程模型中,两个主要的硬件设备分别为CPU和GPU,它们都有自己专用的内存区域。I主机、设备和异构并行编程CPU连同它的计算机RAM被称为主机(Host)。CPU由于其结构特点非常适合运行串行程序。但CPU的问题是,如果其运行至一部分需要大规模并行运算的代码时,......
  • Codeforces Beta Round 96 (Div. 1) -- C. Logo Turtle (dp,记忆化搜索)
    记忆化搜索就是暴力,多一步优化,走过的路别走了。说实话,可能是数据水了,居然能过。constintN=510;strings;intn,ans;boolst[501][501][2][50];voiddfs(intx,intidx,intdir,intk){ if(st[x][idx][dir][k])return; st[x][idx][dir][k]=1;//走过的路不走......
  • Educational Codeforces Round 147 (A-D)
    A.Matching橘子熊:这题太简单了我不想写题面Description给定给一个带问号的字符串,求有多少种可能的数字Input多次询问,一次一个字符串Output对于每次询问,输出可能的数字的总数数据范围与约定2e5次询问,单词询问不超过5个字符思路主要思路签到题大部分情况下,一个......
  • Educational Codeforces Round 39 (Rated for Div. 2) -- D. Timetable (DP)
    写得很折磨人,每次dp都写个一个多小时,写出来明明觉得不难.题目大意:可以进行K次操作,把删除1,进行k次操作后每行第一个1和最后一个1的位置相减的绝对值加1得到的结果最小。做法:每次肯定是要从左删或者从右边删,然后顺着这个思路,先把每行的进行小于等于k次操作时,每行最小......
  • codeforces 559C Gerald and Giant Chess(dp+组合数学)
    题目链接:codeforces559C题目大意:给出一个h*r的矩阵,从左上角走到右下角,中间有一些点不能经过,问不同的路径有多少种?题目分析:首先我们考虑一个n*m的矩阵,从左上角只能向右或向下走能走到右下角的方案数,也就是C(n+m,n),就是一共要走n+m次,选出n次横着走。那么我们定义dp[i]表示在前不经......
  • codeforces 545C C. Woodcutters(dp+二分)
    题目链接:codeforces545C题目大意:给出一些树的位置和高度,每棵树可以砍倒,覆盖[xi−hi,xi]或者覆盖[xi,xi+hi],或者不砍倒,问最多砍倒多少棵树?题目分析:我们记录dp[i]表示选取到i棵树的时候用的最短的区间长度。每次枚举每棵树,二分到最大的不超过当前树位置的个数,然后利用当前树的信息......