| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 598 人关注过本帖
标题:哪位高人帮忙看一下,求完全数程序用vc++2010编译后执行速度比devcpp还慢是 ...
只看楼主 加入收藏
lzb6689
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2007-11-9
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:8 
哪位高人帮忙看一下,求完全数程序用vc++2010编译后执行速度比devcpp还慢是什么原因?
vc++2010中源代码
// 完全数.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <time.h>
using namespace std;
int wqs(long long n,long long *a)
{
    long long i,j,k,l;
    double x,z;
    int r;
    z=n;
    x=sqrt(z);l=(long long)x+1;
    //cout<<"1";
    a[1]=1;r=1;
    i=1;
    while (i<l)
    {
        i++;
        while ((n%i)==0)
        {
            n=n/i;
            //cout<<"x"<<i;
            r++;
            a[r]=i;
        }
        x=sqrt(1.0*n);l=(long long)x+1;
    }
    if(n>1)
    {
        r++;
        a[r]=n;
    }   
     //cout<<"x"<<n;
     return r;
}

int ysfj(long long n,long long *a)
{
    long long i,j,k,l;   
    int r;        
    a[1]=1;r=1;
    i=1;
    l=n/2;
    while (i<l)
    {
        i++;
        if((n%i)==0)
        {
            r++;
            a[r]=i;
        }
        
    }   
     return r;
}


int main(int argc, char *argv[])
{
    clock_t begin,end;
    double t1;
    long long *a;
    long long m,n,h,w;
    int i,k,r;
    cout<<"n=";
    cin>>n;
    cout<<endl;
    begin=clock();
    a=new long long[10000];
    r=wqs(n,a);
    cout<<n<<" = ";
    for(i=1;i<=r;i++)
    {
      if(i==1)    cout<<a[i];else cout<<" x "<<a[i];
    }
    cout<<endl;
    cout<<endl;
    h=0;
    while(h<n)
    {
        h++;
        r=ysfj(h,a);
        w=0;
        for(k=1;k<=r;k++)
        {
            w=w+a[k];
        }
        if (w==h)
        {
            cout<<h<<" = ";
            for(i=1;i<=r;i++)
            {
                if(i==1)    cout<<a[i];else cout<<" + "<<a[i];
            }
            cout<<endl;
        }
    }
    end=clock();
    t1=(double)(end-begin)/CLOCKS_PER_SEC;
    cout<<"t1="<<t1<<endl;
    delete[] a;
    system("pause");
    return 0;
}

搜索更多相关主题的帖子: 应用程序 include 源代码 double 控制台 
2013-10-22 09:45
lzb6689
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2007-11-9
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册

vc++2010编译后执行结果
2013-10-22 09:51
lzb6689
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2007-11-9
收藏
得分:0 
dev-c++源代码:
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <time.h>
using namespace std;
int wqs(long long n,long long *a)
{
    long long i,j,k,l;
    double x,z;
    int r;
    z=n;
    x=sqrt(z);l=(long long)x+1;
    //cout<<"1";
    a[1]=1;r=1;
    i=1;
    while (i<l)
    {
        i++;
        while ((n%i)==0)
        {
            n=n/i;
            //cout<<"x"<<i;
            r++;
            a[r]=i;
        }
        x=sqrt(1.0*n);l=(long long)x+1;
    }
    if(n>1)
    {
        r++;
        a[r]=n;
    }   
     //cout<<"x"<<n;
     return r;
}

int ysfj(long long n,long long *a)
{
    long long i,j,k,l;   
    int r;        
    a[1]=1;r=1;
    i=1;
    l=n/2;
    while (i<l)
    {
        i++;
        if((n%i)==0)
        {
            r++;
            a[r]=i;
        }
        
    }   
     return r;
}


int main(int argc, char *argv[])
{
    clock_t begin,end;
    double t1;
    long long *a;
    long long m,n,h,w;
    int i,k,r;
    cout<<"n=";
    cin>>n;
    cout<<endl;
    begin=clock();
    a=new long long[10000];
    r=wqs(n,a);
    cout<<n<<" = ";
    for(i=1;i<=r;i++)
    {
      if(i==1)    cout<<a[i];else cout<<" x "<<a[i];
    }
    cout<<endl;
    cout<<endl;
    h=0;
    while(h<n)
    {
        h++;
        r=ysfj(h,a);
        w=0;
        for(k=1;k<=r;k++)
        {
            w=w+a[k];
        }
        if (w==h)
        {
            cout<<h<<" = ";
            for(i=1;i<=r;i++)
            {
                if(i==1)    cout<<a[i];else cout<<" + "<<a[i];
            }
            cout<<endl;
        }
    }
    end=clock();
    t1=(double)(end-begin)/CLOCKS_PER_SEC;
    cout<<"t1="<<t1<<endl;
    delete[] a;
    system("pause");
    return 0;
}
2013-10-22 09:51
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:10 
vs2010下:

实际运行效果:

D:\c_source\t7\Debug>t7
n=369

369 = 1 x 3 x 3 x 41

1 = 1
6 = 1 + 2 + 3
28 = 1 + 2 + 4 + 7 + 14
t1=0
请按任意键继续. . .

D:\c_source\t7\Debug>t7
n=25

25 = 1 x 5 x 5

1 = 1
6 = 1 + 2 + 3
t1=0
请按任意键继续. . .


DO IT YOURSELF !
2013-10-22 09:56
lzb6689
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2007-11-9
收藏
得分:0 
devcpp编译后执行结果
图片附件: 游客没有浏览图片的权限,请 登录注册

2013-10-22 09:56
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
vs2010下运行效果

D:\c_source\t7\Debug>t7
n=123456

123456 = 1 x 2 x 2 x 2 x 2 x 2 x 2 x 3 x 643

1 = 1
6 = 1 + 2 + 3
28 = 1 + 2 + 4 + 7 + 14
496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248
8128 = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 127 + 254 + 508 + 1016 + 2032 + 4064
t1=47.234
请按任意键继续. . .




DO IT YOURSELF !
2013-10-22 09:59
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
不知道你的t1是虾米东东

DO IT YOURSELF !
2013-10-22 09:59
lzb6689
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2007-11-9
收藏
得分:0 
呵呵! t1只不过是随便设置的一个double变量而已。
2013-10-22 10:59
lzb6689
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2007-11-9
收藏
得分:0 
呵呵!没说清楚, t1是计算运算所用时间的变量。
2013-10-22 11:01
快速回复:哪位高人帮忙看一下,求完全数程序用vc++2010编译后执行速度比devcpp还 ...
数据加载中...
 
   



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

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