| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我用同样的数学模型写的程序,pascal的过,c++的却TLE,为什么?#include <math.h>
#include <iostream>
using namespace std;
int m,n;
int prnum[39];
int nonum[39];
int testnum[39];
int pp1[39];
int pp2[39];
int ans[100002];
int cal;
int prpoi;
int main()
{
while(cin>>n>>m)
{
prpoi=0;
ans[0]=0;
int temp=m;
bool isprime=true;
for(int i=2;i<=(m+1)/2;i++)
if(temp%i==0)
{int cou=0;isprime=false;
while(temp%i==0){temp/=i;cou++;}
prpoi++;
prnum[prpoi]=i;
nonum[prpoi]=cou;
if(temp==1)break;
}
if(isprime)
{prpoi++;
prnum[prpoi]=m;
nonum[prpoi]=1;
}
/*
for(int i=1;i<=prpoi;i++)
cout<<prnum[i]<<" "<<nonum[i]<<endl;
cout<<endl;
*/
int p1=n-1;
int p2=1;
for(int i=1;i<=prpoi;i++)testnum[i]=0;
for(int j=2;j<=(n+1)/2;j++)
{
int temp;
temp=p1;
for(int i=1;i<=prpoi;i++)
{int cou=0;
while(temp%prnum[i]==0){temp/=prnum[i];cou++;}
pp1[i]=cou;
}
temp=p2;
for(int i=1;i<=prpoi;i++)
{int cou=0;
while(temp%prnum[i]==0){temp/=prnum[i];cou++;}
pp2[i]=cou;
}
bool isin=true;
for(int i=1;i<=prpoi;i++)testnum[i]+=pp1[i]-pp2[i];
/*
cout<<p2+1<<":"<<endl;
for(int i=1;i<=prpoi;i++)cout<<testnum[i]<<" ";
cout<<endl;
*/
for(int i=1;i<=prpoi;i++)
if(testnum[i]<nonum[i]){isin=false;break;}
if(isin)
{
ans[0]++;
ans[ans[0]]=j;
}
p1--;
p2++;
}
// cout<<endl;
int poi;
if(n%2 && ans[ans[0]]==((n+1)/2))poi=ans[0]-1;else poi=ans[0];
for(int i=poi;i>=1;i--)
{ans[0]++;
ans[ans[0]]=n+1-ans[i];
}
cout<<ans[0]<<endl;
for(int i=1;i<=ans[0];i++)cout<<ans[i]<<" ";
cout<<endl;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator