Skip to content

Commit 123d605

Browse files
committed
ugly number
1 parent 6e85698 commit 123d605

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Math/Math.Lib/Math.Lib.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<Compile Include="Properties\AssemblyInfo.cs" />
5454
<Compile Include="ReverseIntegarSln.cs" />
5555
<Compile Include="Sqrtx.cs" />
56+
<Compile Include="UglyNumberSln.cs" />
5657
</ItemGroup>
5758
<ItemGroup>
5859
<Content Include="Floyd%27sTortoiseandHare.jpg" />

Math/Math.Lib/UglyNumberSln.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* ==============================================================================
2+
* 功能描述:UglyNumberSln
3+
* 创 建 者:gz
4+
* 创建日期:2017/5/26 12:23:33
5+
* ==============================================================================*/
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
11+
namespace Math.Lib
12+
{
13+
/// <summary>
14+
/// UglyNumberSln
15+
/// </summary>
16+
public class UglyNumberSln
17+
{
18+
public bool IsUgly(int num)
19+
{
20+
if (num <= 0) return false;
21+
if (num == 1) return true;
22+
while (num >1)
23+
{
24+
if(num%2==0)
25+
num /= 2;
26+
else if (num%3 == 0)
27+
num /= 3;
28+
else if (num%5 == 0)
29+
num /= 5;
30+
else return false;
31+
}
32+
return true;
33+
}
34+
35+
}
36+
}

0 commit comments

Comments
 (0)