蓝桥杯 ADV-189 算法提高 连接乘积

栏目: 编程工具 · 发布时间: 7年前

内容简介:问题描述输出格式每个k占一行

问题描述

192这个数很厉害,用它分别乘以1、2、3,会得到:

192 x 1 = 192

192 x 2 = 384

192 x 3 = 576

把这三个乘积连起来,得到192384576,正好是一个1~9的全排列

我们把上面的运算定义为连接乘积:

m x (1 … n) = k(其中m > 0 且 n > 1,对于上例,m = 192、n = 3、k = 192384576)

即k是把m分别乘以1到n的乘积连接起来得到的,则称k为m和n的连接乘积。

输出格式

每个k占一行

样例输出

显然,结果中应包含一行:

192384576

#include <iostream>
using namespace std;
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int main() {
    int a, b, c, ans;
    cin >> a >> b >> c;
    ans = a * b / gcd(a, b);
    ans = ans * c / gcd(ans, c);
    cout << ans;
    return 0;
}
❤❤点击这里 -> 订阅PAT、蓝桥杯、GPLT天梯赛、LeetCode题解离线版❤❤ 蓝桥杯 ADV-189 算法提高 连接乘积

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Beautiful Code

Beautiful Code

Greg Wilson、Andy Oram / O'Reilly Media / 2007-7-6 / GBP 35.99

In this unique work, leading computer scientists discuss how they found unusual, carefully designed solutions to difficult problems. This book lets the reader look over the shoulder of major coding an......一起来看看 《Beautiful Code》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具