zoukankan      html  css  js  c++  java
  • [codeforces 235]A. LCM Challenge

    [codeforces 235]A. LCM Challenge

    试题描述

    Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.

    But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?

    输入

    The first line contains an integer n (1 ≤ n ≤ 106) — the n mentioned in the statement.

    输出

    Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.

    输入示例

    9

    输出示例

    504

    数据规模及约定

    见“输入

    题解

    对于奇数,那么显然答案是 lcm(n, n-1, n-2),对于偶数,答案只可能是这两种:

    1. lcm(n, n-1, n-3)

    2. lcm(n-1, n-2, n-3)

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <stack>
    #include <vector>
    #include <queue>
    #include <cstring>
    #include <string>
    #include <map>
    #include <set>
    using namespace std;
    
    const int BufferSize = 1 << 16;
    char buffer[BufferSize], *Head, *Tail;
    inline char Getchar() {
        if(Head == Tail) {
            int l = fread(buffer, 1, BufferSize, stdin);
            Tail = (Head = buffer) + l;
        }
        return *Head++;
    }
    int read() {
        int x = 0, f = 1; char c = getchar();
        while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
        while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
        return x * f;
    }
    
    #define LL long long
    int n;
    
    LL gcd(LL a, LL b) { return !b ? a : gcd(b, a % b); }
    LL lcm(LL a, LL b) { return a * b / gcd(a, b); }
    
    int main() {
    	n = read();
    	
    	if(n == 1) return puts("1"), 0;
    	if(n & 1) return printf("%I64d
    ", (LL)n * (n - 1) * (n - 2)), 0;
    	int a1 = n - 3, b1 = n - 1, c1 = n;
    	int a2 = n - 3, b2 = n - 2, c2 = n - 1;
    	printf("%I64d
    ", max(lcm(lcm(a1, b1), c1), lcm(lcm(a2, b2), c2)));
    	
    	return 0;
    }
    
  • 相关阅读:
    iOS版打地鼠游戏源码
    OuNews 简单的新闻客户端应用源码
    安卓DJ113舞曲网应用客户端 项目源码(服务器+客户端)
    博客迁移
    iOS 多张图片保存到相册问题(add multiple images to photo album)
    【转】 iOS 学习之 NSPredicate 模糊、精确、查询
    iOS 设置图片imageView圆角——对图片进行裁剪
    iOS9的那些坑 — — WeiboSDK registerApp启动就崩溃
    关于Debug下的Log打印问题
    Runtime运行时学习(一)
  • 原文地址:https://www.cnblogs.com/xiao-ju-ruo-xjr/p/5813170.html
Copyright © 2011-2022 走看看