110704 Factovisors

import java.util.*;
import static java.lang.Math.*;

public class Main {

private static boolean IsPrime(int x)
{
int mid = (int)(sqrt(x));
for (int i = 2; i <= mid; ++i)
if ((x % i) == 0)
return false;
return true;
}

private static int GetGCD(int n, int m)
{
if (n < m)
return GetGCD(m, n);

if (n == m)
return m;

while (true)
{
int tmp = n % m;
if (tmp == 0)
return m;

n = m;
m = tmp;
}
}

private static boolean IsDividable(int n, int m)
{
if (m == 1)
return true;

if (m == 0)
return false;

if (n == 0)
return false;

boolean needToCheckPrime = true;
while (m > n)
{
if (n <= 2)
return false;

if (needToCheckPrime && IsPrime(m))
return false;

int gcd = GetGCD(n, m);
needToCheckPrime = (gcd > 1) ? true : false;
m /= GetGCD(n, m);
--n;
}

return true;
}

private static void Handle(int n, int m)
{
if (IsDividable(n, m))
System.out.println(m + " divides " + n + "!");
else
System.out.println(m + " does not divide " + n + "!");
}

public static void main(String[] args)
{
Scanner inScanner = new Scanner(System.in);
while (inScanner.hasNextInt())
{
int n = inScanner.nextInt();
int m = inScanner.nextInt();
Handle(n, m);
}
}

}


PC/UVa 题号： 110704/10139 Factovisors

2012-02-28 19:28:54

UVa 10139 - Factovisors

2014-11-04 18:00:33

UVa 10139 Factovisors (阶乘能否整除？)

2014-01-12 10:22:14

JOJ1926:Factovisors

2011-11-22 14:37:24

Factovisors - PC110704

2014-04-13 12:03:22

poj--2649 factovisors

2016-11-19 09:58:20

hoj 1560 - Factovisors

2008-02-04 00:38:00

poj2649 Factovisors 质因数分解

2015-01-20 14:13:27

POJ 2649 Factovisors（素因子分解）

2016-03-01 09:12:56

uva 10139 factovisors

2012-01-19 13:00:55

不良信息举报

110704 Factovisors