Supreme Number

版权声明:菜鸟一枚~~ 有想法可在下面评论, 转载标明出处即可。 https://blog.csdn.net/KLFTESPACE/article/details/82529481

 

//特别坑   371, 713, 731 都不是素数 

/*#include <iostream>
#include <math.h>
using namespace std;
int a[] = {1, 2, 3, 5, 7,11, 13, 17, 23, 31, 37, 53, 71, 73, 113, 131,  137, 173, 311, 317, 371,  713, 731};
int isPrime(long long n)
{	//返回1表示判断为质数,0为非质数,在此没有进行输入异常检测
    float n_sqrt;
    if(n==2 || n==3) return 1;
    if(n%6!=1 && n%6!=5) return 0;
    n_sqrt=floor(sqrt((float)n));
    for(int i=5;i<=n_sqrt;i+=6)
    {
        if(n%(i)==0 | n%(i+2)==0) return 0;
    }
    return 1;
}
int main() {
    int flag;
    long long n;
    // cin >> n;
     for(long long i=0; i<23; i++) {
    if (isPrime(a[i]))
        cout << a[i] << " ";
    else cout << "NO is" << a[i] << endl;
}
    return 0;
}
*/
#include <iostream>
#include <string>
using namespace std;

int a[] = {1, 2, 3, 5, 7,11, 13, 17, 23, 31, 37, 53, 71, 73, 113, 131,  137, 173, 311, 317, 371,  713, 731};

int main()
{
    int N;

    string s;

    cin >> N;

    for(int i=1; i<=N; i++) {
        cin >> s;
        int t = 0;
        int cnt = 0;
              int j=s.size();
              if(j >= 4)
                  t = 1000;
              else
                  for(j = 0; s[j]; j++)
                  {
                      t *= 10;

                      t += s[j]-'0';

                  }

            cout << "Case #" << i << ": ";
     /*       if (t >= 731)
                cout << "731" << endl;
            else if (t >= 713)
                cout << "713" << endl;
            else if (t >= 371)
                cout << "371" << endl;*/
        if (t >= 317)
                cout << "317" << endl;
            else if (t >= 311)
                cout << "311" << endl;
            else if (t >= 173)
                cout << "173" << endl;
            else if (t >= 137)
                cout << "137" << endl;
            else if (t >= 131)
                cout << "131" << endl;
            else if (t >= 113)
                cout << "113" << endl;

            else if (t >= 73)
                cout << "73" << endl;

            else if (t >= 71)
                cout << "71" << endl;
            else if (t >= 53)
                cout << "53" << endl;

            else if (t >= 37)
                cout << "37" << endl;
            else if (t >= 31)
                cout << "31" << endl;
            else if (t >= 23)
                cout << "23" << endl;
            else if (t >= 17)
                cout << "17" << endl;
            else if (t >= 13)
                cout << "13" << endl;
            else if (t >= 11)
                cout << "11" << endl;
            else if (t >= 7)
                cout << "7" << endl;
            else if (t >= 5)
                cout << "5" << endl;
            else if (t >= 3)
                cout << "3" << endl;

            else
                cout << "2" << endl;

        }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/KLFTESPACE/article/details/82529481