| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1690 人关注过本帖
标题:C语言关于求两个数的共同因子问题!!!
取消只看楼主 加入收藏
LeslieCh
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-11-27
结帖率:77.78%
收藏
已结贴  问题点数:20 回复次数:3 
C语言关于求两个数的共同因子问题!!!
4128: Tao God and Jiong King II
Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 303  Solved: 22

Description
Today Tao God invite Jiong King to join his party of heaven.It’s wellknown to us,Tao God is the leader of heaven and Jiong King is the leader of hell.To welcome for Jiong King’coming,Tao God come up with a game to play with Jiong King.Tao God select a number A and Jiong King select a number B.Their value of happiness is the sum of the common divisors of A and B.
If X can be divided by Y, we call Y is a divisor of X. For example, 3 is a divisor of 6.Now, give you Tao God’selection A and Jiong King’selection B,please help them calculate their value of happiness.



Input
The input file consists of multipe test cases.

Each tast case only contains two numbers A and B.

(1 <= A, B <= 100000000)

 


Output
Output their value of happiness.




Sample Input
5 10
6 8

Sample Output
6
3

HINT

我写的代码,交上去是超时的。。。这道题要用什么方法解?
#include<stdio.h>
#include<string.h>
int main()
{
    long int A,B,t,i;
    int s;
    while(scanf("%d%d",&A,&B)!=EOF)
    {
        if(A>B)
        {A=t;A=B;B=t;}
        s=0;
        for(i=1;i<=A;i++)
        {
            if(A%i==0&&B%i==0)
            {
                s+=i;
            }
        }
        printf("%d\n",s);
    }
    return 0;
}


搜索更多相关主题的帖子: Memory heaven welcome happiness invite 
2014-01-14 11:17
LeslieCh
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-11-27
收藏
得分:0 
2014-01-14 11:17
LeslieCh
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-11-27
收藏
得分:0 
回复 4楼 pangshch
不行,还是TLE啊。。。。
2014-01-14 18:44
LeslieCh
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-11-27
收藏
得分:0 
回复 6楼 pangshch
灰常感谢,优化后的AC啦
2014-01-14 19:27
快速回复:C语言关于求两个数的共同因子问题!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013511 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved