zoukankan      html  css  js  c++  java
  • One Gym

    https://vjudge.net/problem/Gym-102680D/origin

    https://vjudge.net/contest/396206#problem/D

    Hooray! It's time for the obligatory problem concerning the random mathematical properties of an arbitrary number! And since today is the 1st Brookfield Computer Programming Challenge, this year's number is 1!

    One is a pretty unique number. Of course, it is the multiplicative identity (that is x*1 = x), as well as the smallest natural number. It is sometimes called the loneliest number, the maximum value of Random.nextDouble(), the magnitude of any unit vector, and the only positive number that is a valid digit in any base, as well as power of 2 itself (20=120=1, oh joy!). It is also both the second and third Fibonacci number (0, 1, 1, 2, 3, 5, 8...). In fact, it is the only number to appear a prime number of times in the Fibonacci sequence.

    Speaking of primes, whether or not 1 is a prime number has been discussed quite fervently among mathematicians. A prime is a number with exactly two unique natural factors. A composite number is a number with more than two unique natural factors. 7, for example, has factors of 1 and 7, but no others, making it prime. 9 has factors of 1, 3, and 9, making it composite. 1, however, is only divisible by 1, and is therefore neither prime nor composite. Interestingly, 1 is the only number with this property.

    Given nn natural numbers, decide whether each of them is prime, composite, or neither. Be careful that your program finishes execution within 5 seconds for any valid input.

    Input

    The first line will contain an integer nn, the number of natural numbers to compute. nn lines follow, each containing a single integer qiqi

    1n1001≤n≤100

    1qi21091≤qi≤2∗109

    Output

    Output nn lines, each containing either "Prime", "Composite", or "Neither", depending on the state of each number.

    Example

    Input
    4
    9
    1
    2017
    1000000007
    
    Output
    Composite
    Neither
    Prime
    Prime
    

    Note

    9 has 3 factors: 1,3, and 9, and is therefore composite.

    1 is discussed in the problem statement.

    2017 only has factors of 1 and itself, and is therefore prime.

    1000000007 also happens to be prime for the same reason.

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<bitset>
    #include<cassert>
    #include<cctype>
    #include<cmath>
    #include<cstdlib>
    #include<ctime>
    #include<deque>
    #include<iomanip>
    #include<list>
    #include<map>
    #include<queue>
    #include<set>
    #include<stack>
    #include<vector>
    #include <vector>
    #include <iterator>
    #include <utility>
    #include <sstream>
    #include <limits>
    #include <numeric>
    #include <functional>
    using namespace std;
    #define gc getchar()
    #define mem(a) memset(a,0,sizeof(a))
    #define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl;
    
    #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    typedef long long ll;
    typedef unsigned long long ull;
    typedef long double ld;
    typedef pair<int,int> pii;
    typedef char ch;
    typedef double db;
    
    const double PI=acos(-1.0);
    const double eps=1e-6;
    const int inf=0x3f3f3f3f;
    //const int maxn=1e5+10;
    const int maxn = 5010;
    //const int maxm=100+10;
    const int N=1e6+10;
    const int mod=1e9+7;
    
    
    bool isPrime(int Check)
    {
    	int min = Check < sqrt(Check)+1 ? Check : sqrt(Check)+1;
     	for(int i = 2;i<min;i++)
    	{
    		if(Check % i == 0)
    		{
    			return 0;
    		}
    	}
    	return 1;
    }
    
    int main()
    {
    	int T = 0;
    	cin >> T;
    	while(T--)
    	{
    		int Check;
    		cin >> Check;
    		if(Check == 1)
    		{
    			cout << "Neither" << endl;
    			continue;
    		}
    		if( isPrime(Check) )
    		{
    			cout << "Prime" << endl;
    		}
    		else
    		{
    			cout << "Composite" << endl;
    		}
    	}
    	return 0;
    } 
    

      

  • 相关阅读:
    索引碎片整理
    SQL Server表分区案例
    SQL分页查询语句
    SQL Server表分区
    SQL Server优化
    SQLSERVER中WITH(NOLOCK)详解
    作业四
    第三次k均值
    机器学习第二次作业
    机器学习
  • 原文地址:https://www.cnblogs.com/SutsuharaYuki/p/13813541.html
Copyright © 2011-2022 走看看