Finding LCM LightOJ - 1215 (水题)

这题和这题一样。。。。。。只不过多了个数。。。

Finding LCM

LightOJ - 1215

https://www.cnblogs.com/WTSRUVF/p/9316412.html

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(a, n) for(int i=1; i<=n; i++)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 10010, INF = 0x7fffffff;
LL gcd(LL a, LL b)
{
    return b==0?a:gcd(b, a%b);
}

int main()
{
    int T, kase = 0;
    cin>> T;
    while(T--)
    {
        LL a, b, L;
        cin>> a >> b >> L;
        printf("Case %d: ", ++kase);
        LL c = a * b / gcd(a, b);
        if(L % c)
        {
            cout<< "impossible" <<endl;
            continue;
        }
        LL d = L / c;
        while(gcd(c, d) != 1)
        {
            LL m = gcd(c, d);
            c /= m;
            d *= m;
        }
        cout<< d <<endl;
    }

    return 0;
}

原文地址:https://www.cnblogs.com/WTSRUVF/p/9350242.html

时间: 2024-07-29 19:39:06

Finding LCM LightOJ - 1215 (水题)的相关文章

LightOJ 1215 Finding LCM(数论)

题意  已知LCM(a, b, c) = L 和 a.b.L   求最小的满足等式的c. 把数展开为素因子积的形式后 GCD(a,b)就是a,b的公共素因子取在a.b中的较小指数 LCM(a,b)就是a,b的所有素因子取在a.b中的较大指数 令m = LCM(a,b)  那么问题转化为了求最小的c满足 LCM(m, c) = L 那么最小的c就是L中不在m中的素因子和L中指数大于m中指数的素因子取在L中的指数即积 #include <bits/stdc++.h> using namespace

LightOJ - 1215 Finding LCM

Finding LCM 已知a, b, c的最小公倍数为L, 给你a,b,问你是否存在最小的c满足题意,不存在输出impossible 素数分解 1 #include <cmath> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #define INF 0x3f3f3f3f 6 #define MOD 1000000007 7 using namespace std; 8

LightOJ 1166 Old Sorting 置换群 或 贪心 水题

LINK 题意:给出1~n数字的排列,求变为递增有序的最小交换次数 思路:水题.数据给的很小怎么搞都可以.由于坐标和数字都是1~n,所以我使用置换群求循环节个数和长度的方法. /** @Date : 2017-07-20 14:45:30 * @FileName: LightOJ 1166 贪心 或 置换群 水题.cpp * @Platform: Windows * @Author : Lweleth ([email protected]) * @Link : https://github.co

Lightoj 1112 - Curious Robin Hood 【单点改动 + 单点、 区间查询】【树状数组 水题】

1112 - Curious Robin Hood PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 64 MB Robin Hood likes to loot rich people since he helps the poor people with this money. Instead of keeping all the money together he does another trick.

Lightoj 1112 - Curious Robin Hood 【单点修改 + 单点、 区间查询】【树状数组 水题】

1112 - Curious Robin Hood PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 64 MB Robin Hood likes to loot rich people since he helps the poor people with this money. Instead of keeping all the money together he does another trick.

poj 2369 Permutations 置换水题

找循环节求lcm就够了,若答案是12345应该输出1,被坑了下. #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cmath> using namespace std; #define INF 0x3FFFFFF #define MAXN 2222 #define eps 1e-6 i

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

hdu 3443(水题,公式)Shift Number

题意: 给一个数n,求最小的数生成的shift number等于n. shift number就是一个数x,x*10,x*100-..这样的和. 思路 把那个公式处理一下,其实就是X*(形如11111-.)这样的一个式子,那么找一个最大的11111-.,x就是最小了.水题 复杂度: O(len(n)) 参考code: /* #pragma warning (disable: 4786) #pragma comment (linker, "/STACK:0x800000") */ #in

poj 1979 dfs水题

// 练练水题,夯实基础吧 #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib