意甲冠军:1,3是完美的数,假定a,b是完美的数,然后,2+a*b+2*a+2*b,结论认为,n无论是完美的数字。
解法:開始仅仅看出来2+a*b+2*a+2*b=(a+2)*(b+2)-2,没推出很多其它结论,囧。没办法,仅仅能暴力将全部的完美数求出来然后查表。正解是c+2=(a+2)*(b+2);完美数都是有质因子3或5组成的(5本身除外);
自己暴力代码:
/****************************************************** * author:xiefubao *******************************************************/ #pragma comment(linker, "/STACK:102400000,102400000") #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <queue> #include <vector> #include <algorithm> #include <cmath> #include <map> #include <set> #include <stack> #include <string.h> //freopen ("in.txt" , "r" , stdin); using namespace std; #define eps 1e-8 #define zero(_) (abs(_)<=eps) const double pi=acos(-1.0); typedef long long LL; const int Max=1010; const int INF=1000000000; LL num[Max]; int help[Max]; LL get(int l,int r) { return 2*(num[l]+1)*(num[r]+1)-num[l]*num[r]; } struct point { LL ans; int h; }; bool operator<(const point& a,const point& b) { return a.ans>b.ans; } priority_queue<point> pri; int main() { num[0]=1; num[1]=3; point p; p.ans=7; p.h=0; pri.push(p); p.ans=23; p.h=1; pri.push(p); for(int i=0; i<Max; i++) help[i]=i; help[0]=1; help[1]=2; int po=2; while(pri.top().ans<=INF) { point ptop=pri.top(); pri.pop(); if(num[po-1]==ptop.ans) { point p; p.ans=get(ptop.h,help[ptop.h]); p.h=ptop.h; pri.push(p); help[ptop.h]++; continue; } point p; p.ans=get(ptop.h,help[ptop.h]); p.h=ptop.h; pri.push(p); help[ptop.h]++; // cout<<ptop.ans<<" "; num[po++]=ptop.ans; p.ans=get(po-1,po-1); p.h=po-1; pri.push(p); help[po-1]=po; } int t; while(scanf("%d",&t)==1) { if(binary_search(num,num+po,t)) puts("Yes"); else puts("No"); } return 0; }
版权声明:本文博主原创文章,博客,未经同意不得转载。