完数 &&http://acm.hdu.edu.cn/showproblem.php?pid=1406
2012-07-12 19:24
513 查看
求10000以内的完数,打表即可。。。
AC代码:
在打表时一定要注意剪枝,即剪去明显不符合要求的情况(这个一定要多思考,考虑完全)。。。。。
AC代码:
#include<iostream> #include<cstdio> #include<string.h> #include<string> #include<cmath> #define N 10005 using namespace std; bool vis ={1,1}; int prime ; /*void fun() { //is_prime筛法求素数 int res=0; int m=sqrt(N+0.5); for(int i=2;i<=m;++i) if(!vis[i]) { prime[res++]=i; for(int j=i*i;j<=N;j+=i) vis[j]=1; } for(int i=6;i<=N;++i) { if(!vis[i]) continue; int ans=i; long long sum=1; for(int j=0;j<=sqrt(i+0.5)&&ans>=prime[j]&&prime[j]>0;++j) { if(ans%prime[j]==0) { long long cnt=1,s=1; while(ans%prime[j]==0) { s*=prime[j]; cnt+=s; ans/=prime[j]; } sum*=cnt; } if(!vis[ans]) sum*=(ans+1); if(sum>i) break; } if(sum==2*i) cout<<i<<endl; } }*/ int s[]={6,28,496,8128}; int main() { //fun(); int T; scanf("%d",&T); while(T--) { int a,b; scanf("%d%d",&a,&b); int sum=0; for(int i=0;i!=4;++i) if(s[i]>=a&&b>=s[i]||a>=s[i]&&b<=s[i]) sum++; printf("%d\n",sum); }return 0; }
在打表时一定要注意剪枝,即剪去明显不符合要求的情况(这个一定要多思考,考虑完全)。。。。。
相关文章推荐
- Substrings &&http://acm.hdu.edu.cn/showproblem.php?pid=1238
- Trouble&&http://acm.hdu.edu.cn/showproblem.php?pid=4334
- To The Max &&http://acm.hdu.edu.cn/showproblem.php?pid=1081
- A C&&http://acm.hdu.edu.cn/showproblem.php?pid=1570
- I NEED A OFFER! &&http://acm.hdu.edu.cn/showproblem.php?pid=1203
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=791&pid=1001&ojid=0
- Clairewd’s message&&http://acm.hdu.edu.cn/showproblem.php?pid=4300
- 找规律。。&&http://acm.hdu.edu.cn/showproblem.php?pid=1097
- Quoit Design&&http://acm.hdu.edu.cn/showproblem.php?pid=1007
- Holedox Eating &&http://acm.hdu.edu.cn/showproblem.php?pid=4302
- find the safest road&&http://acm.hdu.edu.cn/showproblem.php?pid=1596
- The 36th ACM/ICPC Asia Regional Beijing Site&&http://acm.hdu.edu.cn/showproblem.php?pid=4046
- 二分查找求函数的区间最小值&&http://acm.hdu.edu.cn/showproblem.php?pid=2899
- 最小路径覆盖&&http://acm.hdu.edu.cn/showproblem.php?pid=4160
- Robberies&&http://acm.hdu.edu.cn/showproblem.php?pid=2955
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=963&pid=1019&ojid=1
- http://acm.hdu.edu.cn/showproblem.php?pid=1020&&encoding
- Text Reverse&&http://acm.hdu.edu.cn/showproblem.php?pid=1062
- Buy the Ticket&&http://acm.hdu.edu.cn/showproblem.php?pid=1133
- Number Sequence&&http://acm.hdu.edu.cn/showproblem.php?pid=1005