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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
S
Securelist
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
AI
AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Schneier on Security
Schneier on Security
Attack and Defense Labs
Attack and Defense Labs
Vercel News
Vercel News
腾讯CDC
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
量子位
S
Schneier on Security
Hacker News: Ask HN
Hacker News: Ask HN
Cyberwarzone
Cyberwarzone
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
T
Tenable Blog
PCI Perspectives
PCI Perspectives
MyScale Blog
MyScale Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
W
WeLiveSecurity
N
News | PayPal Newsroom
P
Proofpoint News Feed
O
OpenAI News
C
CERT Recently Published Vulnerability Notes
B
Blog
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Spread Privacy
Spread Privacy

博客园 - 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)  评论()    收藏  举报