惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
Scott Helme
Scott Helme
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 最新话题
S
Security @ Cisco Blogs
Webroot Blog
Webroot Blog
S
Security Affairs
H
Hacker News: Front Page
TaoSecurity Blog
TaoSecurity Blog
W
WeLiveSecurity
G
GRAHAM CLULEY
T
Tenable Blog
Schneier on Security
Schneier on Security
S
Securelist
Cyberwarzone
Cyberwarzone
P
Privacy International News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Schneier on Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
Recent Commits to openclaw:main
Recent Commits to openclaw:main
O
OpenAI News
N
News and Events Feed by Topic
AWS News Blog
AWS News Blog
C
Cisco Blogs
T
Threat Research - Cisco Blogs
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
美团技术团队
Martin Fowler
Martin Fowler
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
D
DataBreaches.Net
博客园_首页
MyScale Blog
MyScale Blog
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
P
Proofpoint News Feed
J
Java Code Geeks
SecWiki News
SecWiki News
P
Palo Alto Networks Blog
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org

博客园 - Love Fendi

性能优化系列---查询高cup的sql State模式学习 8.17--8.24积累 sql server 2005 analysis service step by step(三):创建父子维度 sql server 2005 analysis service step by step(二):创建时间维度 sql serve 2005 analysis service step by step(一):创建标准维度 算法练习五:求数组中第k大的数 算法练习四:求N!不溢出 算法练习三:奇偶分割 算法练习二:二分查找 数据库锁 索引优化 生成验证码,同时异步获取加密后的验证码 自定义控件中与脚本资源集成的若干处理方式 一条语句删除表中某字段重复的数据 动态按需异步加载js文件 在Nhibernate中使用Json.net中出现Self referencing loop的错误的处理 JQuery学习笔记 c#委托事件 入门
算法练习一:最大公约数与最小公倍数
Love Fendi · 2009-04-01 · via 博客园 - Love Fendi

算法练习一:最大公约数与最小公倍数

 

 static void Main(string[] args)
        {

            Stopwatch s1 = new Stopwatch();
            s1.Start();
            int a = GetMaxDividen(2000, 1500);
            s1.Stop();
            Console.WriteLine(a);
            Console.WriteLine(s1.ElapsedTicks);

            Stopwatch s2 = new Stopwatch();
            s2.Start();
            int b = GetMaxDividen2(2000, 1500);
            s2.Stop();
            Console.WriteLine(b);
            Console.WriteLine(s2.ElapsedTicks);
            //Console.WriteLine(GetMaxDividen2(15, 20));

            Console.WriteLine(getMinBei(33,55));
            Console.Read();
        }

        public static int GetMaxDividen(int a, int b)
        {
            int c = a % b;
            while (c != 0)
            {
                a = b;
                b = c;
                c = a % b;
            }
            return b;
        }

        public static int GetMaxDividen2(int a, int b)
        {
            int c = 0;
            if (a < b)
            {
                //swap(a, b);
                c = a;
                a = b;
                b = c;
            }
            for (int i = b; a > 1; i--)
            {
                if (a % i == 0 && b % i == 0)
                {
                    c = i;
                    break;
                }
            }

            return  c;
        }

        static int getMinBei(int a, int b)
        {
            int c = GetMaxDividen(a, b);
            return a * b / c;
        }

posted on 2009-04-01 16:57  Love Fendi  阅读(491)  评论()    收藏  举报