正文

统计并输出能被3整除或能被5整除或能被7整除的所有三位数2005-11-06 20:01:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/boxer/6655.html

分享到:

long Div357_m(long m, long n)
{
    long    count = 0;
    int     start, end;
 static int inc[16] = {0, 1, 2, 2, 3, 3, 3, 4, 5, 5, 5, 6, 6, 7, 8, 8};

    int   i;
 
    start = (m/3+1)*3;
    for(i=start; i<=n; i+=3)
 {
        ++count;
 }
 
    start = (m/15+1)*15+1;
    end = n/15*15;
    for(i=start; i<=end; i+=15)    
    {
        count += 2;
    }
   
    long    temp = start - m;
    if(temp <= 5)
        ;
    else if(temp <= 10)
 {
        count += 1;
 }
    else
 {
        count += 2;
 }
 
    temp = n - end;
    if(temp < 5)
        ;
    else if(temp < 10)
 {
        count += 1;
 }
    else
 {
        count += 2;
 }
 
    start = (m/105+1)*105+1;
    end = n/105*105;
   
    for(i=start; i<=end; i+= 105)
 {
        count += 8;
 }
 
    temp = start - m - 1;
 count += inc[temp/7];  
   
    temp = n-end;
 count += inc[temp/7];  
   
    return count;
}

阅读(5807) | 评论(2)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册