我們將30/50 = 3/5這樣的分數作爲普通個例。
一共有四個這樣的非普通分數,其值小於1,並且包括分子和分母都包括2位數。
如果將這四個分數的乘積約分到最簡式,分母是多少?
public class Problem33
{
public static void main(String[] args)
{
long start = System.currentTimeMillis();
System.out.print("answer: ");
howmany();
long end = System.currentTimeMillis();
System.out.print("time: ");
System.out.println(end - start);
}
static void howmany()
{
int up = 1;
int down = 1;
for (int i = 11; i <= 99; i++)
{
if (i % 10 == 0)
{
continue;
}
for (int j = 11; j <= 99; j++)
{
if (i >= j || j % 10 == 0)
{
continue;
}
int i1 = i % 10;
int i2 = i / 10;
int j1 = j % 10;
int j2 = j / 10;
if (i1 == j2)
{
if (Math.abs((double)i / j - (double)i2 / j1) < 0.0000001)
{
up *= i2;
down *= j1;
}
}
else if (i2 == j1)
{
if ( Math.abs((double)i / j - (double)i1 / j2 )<0.0000001)
{
up *= i1;
down *= j2;
}
}
}
}
for (int i = up;i > 0; i--)
{
if (down % i == 0)
{
down /= i;
up /= i;
break;
}
}
System.out.println(down);
}
}
answer: 100
time: 1