3 条题解

  • 3
    @ 2022-12-11 11:44:42

    AC代码,放心使用

    #include <bits/stdc++.h>
    using namespace std;
    int n;
    int zs(int a)
    {
    	for (int i = 2; i < a; i += 1)
    	{
    		if (a % i == 0)
    		{
    			return 0;
    		}
    	}
    	return 1;
    }
    int main()
    {
    	cin >> n;
    	for (int i = 2; i <= sqrt(n); i += 1)
    	{
    		if ((zs(i)) && (zs(n / i)))
    		{
    			if (n % i == 0)
    			{
    				cout << "It's a Tongtong number." << endl;
    				return 0;	
    			}
    		}
    	}
    	cout << "It's not a Tongtong number." << endl;
    	return 0;
    }
    
    • 1
      @ 2022-4-16 16:30:45

      #include <bits/stdc++.h> int prime ( int a ) ; using namespace std ; int main ( ) { int z , n ; cin >> n ; if ( prime ( n ) == true || n == 1 ) { cout << "It's not a Tongtong number." ; return 0 ; } for ( int i = 2 ; i <= n / 2 ; i++ ) { z = i ; if ( prime ( z ) == true ) { if ( n % z == 0 && prime ( n / z ) == true ) { cout << "It's a Tongtong number." ; return 0 ; } else if ( n % z == 0 && prime ( n / z ) == false ) { cout << "It's not a Tongtong number." ; return 0 ; } } } cout << "It's not a Tongtong number." ; } int prime ( int a ) { bool flag = true ; if ( a == 1 ) { flag = false ; } for ( int i = 2 ; i * i <= a ; i++ ) { if ( a % i == 0 ) { flag = false ; break ; } } return flag ; }

      • 0
        @ 2023-7-13 11:46:01

        #include <bits/stdc++.h> using namespace std; int n; int zs(int a) { for (int i = 2; i < a; i += 1) { if (a % i == 0) { return 0; } } return 1; } int main() { cin >> n; for (int i = 2; i <= sqrt(n); i += 1) { if ((zs(i)) && (zs(n / i))) { if (n % i == 0) { cout << "It's a Tongtong number." << endl; return 0; } } } cout << "It's not a Tongtong number." << endl; return 0; }

        • 1

        信息

        ID
        151
        时间
        1000ms
        内存
        16MiB
        难度
        7
        标签
        递交数
        293
        已通过
        69
        上传者