反素数

打表

这道题一看只输入一个变量,并且感觉反素数应该不会太多,就打一打看看,发现确实很少,打出来就好了!!
直接N*sqrt(N)打出表。

code:

#include<bits/stdc++.h>
using namespace std;
int p[500]={1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560,10080,15120,20160,25200,27720,45360,50400,55440,83160,110880,166320,221760,277200,332640,498960,554400,665280,720720,1081080,1441440,2162160,2882880,3603600,4324320,6486480,7207200,8648640,10810800,14414400,17297280,21621600,32432400,36756720,43243200,61261200,73513440,110270160,122522400,147026880,183783600,245044800,294053760,367567200,551350800,698377680,735134400,1102701600,1396755360,2001000000};
int main()
{
    int n;
    cin>>n;
    int ans;
    for(int i=0;;i++)
    {
        if(p[i]>n) {
            cout<<p[i-1]<<endl;
            return 0;
        }
    }
}

总结:

遇到看起来很有毒的题目可以打表!!打表不能纯粹的暴力,要动动脑子,优化一下,除非你有长者之力,打一年如同一秒

posted @ 2018-09-26 17:00  Splitor  阅读(186)  评论(0编辑  收藏  举报