UVA 11388 GCD LCM 思维题==

根本用不上lcm gcd什么的==

The GCD of two positive integers is the largest integer that divides both the integers without any remainder. The LCM of two positive integers is the smallest positive integer that is divisible by both the integers. A positive integer can be the GCD of many pairs of numbers. Similarly, it can be the LCM of many pairs of numbers. In this problem, you will be given two positive integers. You have to output a pair of numbers whose GCD is the first number and LCM is the second number.

 

Input

The first line of input will consist of a positive integer TT denotes the number of cases. Each of the next T lines will contain two positive integer, G and L.

 

Output

For each case of input, there will be one line of output. It will contain two positive integers a and ba ≤ b, which has a GCD of G and LCM ofL. In case there is more than one pair satisfying the condition, output the pair for which a is minimized. In case there is no such pair, output -1.

 

Constraints

-           T ≤ 100

-           Both and will be less than 231.

 

Sample Input

Output for Sample Input

2

1 2

3 4

1 2

-1

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long prime[100000],num_prime=0;
bool isnotprime[200000004];
//int a[100000],b[100000];
void init()
{
     memset(isnotprime,false,sizeof(isnotprime));
     long  maxn=200000000;
     for(long i=2;i<maxn;i++)
     {
          if(!isnotprime[i])
               prime[num_prime++]=i;
          for(long j=0;j<num_prime&&i*prime[j]<maxn;j++)
          {
               isnotprime[i*prime[j]]=true;
               if(!(i%prime[j])) break;
          }
     }
}
int gcd(int a,int b)
{
     return b?gcd(b,a%b):a;
}
int main()
{
    //freopen("cin.txt","r",stdin);
    int l,g,n,GCD,LCM,i0,j0;
    while(~scanf("%d",&n))
    {
         while(n--)
         {
              scanf("%d%d",&g,&l);
              int sum=0;
              if(l%g)
              {
                   printf("-1\n");
                   continue;
              }
              /*init();
             // memset(a,0,sizeof(a));
              //memset(b,0,sizeof(b));
              int mark=0;
              for(int i=0;i<num_prime&&prime[i]<=g;i++)
              {
                   int numa=0,numb=0;
                   if(g%prime[i]==0&&l%prime[i]==0)
                   {
                        while(g%prime[i]==0)
                         numa++,g/=prime[i];
                        while(l%prime[i]==0)
                         numb++,l/=prime[i];
                         if(numa>numb)
                         {
                              mark=1;
                              break;
                         }
                   }
                   else if(g%prime[i]==0&&l%prime[i])
                   {
                        mark=1;
                        break;
                   }
              }
              if(mark==1) printf("-1\n");*/
              else
              {
                   printf("%d %d\n",g,l);
              }
         }
    }
    return 0;
}

有用的没几行==
全部评论

相关推荐

uu们,拒offer时hr很生气怎么办我哭死
爱睡觉的冰箱哥:人家回收你的offer,或者oc后没给你发offer的时候可不会愧疚你,所以你拒了也没必要愧疚他。
点赞 评论 收藏
分享
牛客84809583...:举报了
点赞 评论 收藏
分享
争当牛马还争不上
码农索隆:1.把简历改哈 2.猛投,狠投 3.把基础打牢 这样你在有机会的时候,才能抓住
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务