zoukankan      html  css  js  c++  java
  • 最小公倍数 (Benefit,UVa 11889)

     1 #include <iostream>
     2 #include <string.h>
     3 #include <string>
     4 #include <fstream>
     5 #include <algorithm>
     6 #include <stdio.h>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #include <cmath>
    11 using namespace std;
    12 const double eps = 1e-8;
    13 const int INF=0x7fffffff;
    14 #define MAXN 10000002
    15 typedef long long LL;
    16 int vis[MAXN];
    17 int prime[700000];
    18 
    19 void sieve(int n)
    20 {
    21     int m=(int)sqrt(n+0.5);
    22     memset(vis,0,sizeof(vis));
    23     for(int i=2;i<=m;i++)if(!vis[i])
    24     for(int j=i*i;j<=n;j+=i)vis[j]=1;
    25 }
    26 
    27 int gen_prime(int n)
    28 {
    29     sieve(n);
    30     int c=0;
    31     for(int i=2;i<=n;i++)if(!vis[i])
    32         prime[c++]=i;
    33     return c;
    34 }
    35 
    36 LL gcd(LL a,LL b)
    37 {
    38     return b==0?a:gcd(b,a%b);
    39 }
    40 
    41 int main()
    42 {
    43     int T;scanf("%d",&T);
    44     LL a,b,c;
    45     while(T--)
    46     {
    47         cin>>a>>c;
    48         if(c%a!=0)printf("NO SOLUTION
    ");
    49         else
    50         {
    51         b=c/a;
    52         LL temp=b;
    53         while(temp!=1)
    54         {
    55             temp=gcd(b,a);
    56             b*=temp;
    57             a/=temp;
    58         }
    59         cout<<b<<endl;
    60         }
    61     }
    62     return 0;
    63 }

    c/a=b/gcd(a,b) 找出a与b/gcd(a,b)所用相同的质因子 乘上b/gcd(a,b)即是最小的b

  • 相关阅读:
    小记面向对象
    公司分层思想的演化历程
    我对uml类图关系的理解
    cms真实问题的来源以及模拟解决方案
    HTTP 协议基础
    Requests库
    接口测试概念
    Python中的strip()函数的用法
    Robot Framework环境搭建
    Python unittest excel数据驱动
  • 原文地址:https://www.cnblogs.com/TO-Asia/p/3203532.html
Copyright © 2011-2022 走看看