5 条题解

  • 1
    @ 2024-9-23 12:21:00

    思路

    边取边模。

    时间复杂度:

    O(n)O(n)

    空间复杂度:

    O(1)O(1)

    Code

    #include<bits/stdc++.h>
    using namespace std;
    int n,m=1;
    int main(){
    	cin>>n;
    	if(n==0){cout<<"YES";return 0;}
    	for(int i=1;i<=n;i++){
    		m*=i;
    		m=m%(n+1);
    	}
    	if(m==0) cout<<"YES";
    	else cout<<"NO";
    	return 0;
    }
  • 0
    @ 2025-2-5 19:20:15

    思路

    直接按照题目模拟即可。

    但是,19!爆了int,不太确定是否爆了long long,所以就用__int128存了。

    注意:__int128不支持输入输出,只能在64位编译器中使用,且是gcc/g++自带的类型。

    时间复杂度:

    O(n)O(n)

    空间复杂度:

    O(n)O(n)

    Code

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        int n;
        __int128 sum=1;
        cin>>n;
        for(int i=2;i<=n;i++)sum*=i;
        if(sum%(n+1)==0)cout<<"YES";
        else cout<<"NO";
        return 0;
    }
    
    • 0
      @ 2025-1-11 11:21:44

      思路

      暴力出奇迹,打表出省一

      解题方法

      一边判断一边走

      复杂度

      全是判断包是O(1)

      时间复杂度:O(1)O(1)

      空间复杂度: O(1)O(1)

      Code

      #include<bits/stdc++.h>
      using namespace std;
      int main(){
          int a;
          cin>>a;
          if(a==1)cout<<"NO";
          else if(a==2)cout<<"NO";
          else if(a==3)cout<<"NO";
          else if(a==4)cout<<"NO";
          else if(a==6)cout<<"NO";
          else if(a==10)cout<<"NO";
          else if(a==12)cout<<"NO";
          else if(a==16)cout<<"NO";
          else if(a==18)cout<<"NO";
          else cout<<"YES";
          return 0;
      }
      
      • -1
        @ 2024-9-23 12:22:48

        思路

        打表。

        提前算好。

        时间复杂度:

        O(1)O(1)

        空间复杂度:

        O(1)O(1)

        Code

        #include<bits/stdc++.h>
        using namespace std;
        string s[20]={"YES","NO","NO","NO","NO",
        "YES","NO","YES","YES","YES",
        "NO","YES","NO","YES","YES",
        "YES","NO","YES","NO","YES"};
        int main()
        {
        	int n;
        	cin>>n;
        	cout<<s[n]<<endl;
        	return 0;
        }
        • -5
          @ 2024-9-18 12:37:02

          O(1)水过

          思路

          暴力出奇迹,打表出省一

          解题方法

          将0!~20!依次除1~21

          复杂度

          时间复杂度:

          O(1)O(1)

          空间复杂度:

          O(1)O(1)

          Code

          #include<bits/stdc++.h>
          using namespace std;
          string s[20]={"YES","NO","NO","NO","NO",
          "YES","NO","YES","YES","YES",
          "NO","YES","NO","YES","YES",
          "YES","NO","YES","NO","YES"};
          int main()
          {
          	int n;
          	cin>>n;
          	cout<<s[n]<<endl;
          	return 0;
          }
          
          • 1

          信息

          ID
          54
          时间
          1000ms
          内存
          512MiB
          难度
          1
          标签
          递交数
          443
          已通过
          290
          上传者