4 solutions

  • 0
    @ 2022-1-18 15:49:45

    同余,余就完了

    #include<iostream>
    #include<cmath>
    using namespace std;
    
    long long int n,c,ans=1,a[119];
    
    int main(){
    	while(cin>>n>>c){
    		ans=1;
    		for(int i=0;i<n;i++){
    			cin>>a[i];
    			ans*=(a[i]%c);
    			ans%=c;
    		}
    		 cout<<ans<<endl;
    	}
    	 return 0;
    }
    
    • 0
      @ 2022-1-14 15:23:01

      只需要每输入一个数,将它按照相关步骤走就对了:

      #include<bits/stdc++.h>
      using namespace std;
      typedef long long ll;
      const int N = 1e6+5;
      int main()
      {
      	ll n,m;
      	while(cin>>n>>m)
      	{
      		ll pp=1;
      		while(n--)
      		{
      			ll a;
      			cin>>a;
      			pp=((a%m)*(pp%m))%m;
      		}	
      	cout<<pp<<endl;
      
      	}
      	return 0;
      }
      
      • 0
        @ 2022-1-5 19:54:40
        #include<stdio.h>
        int main()
        {
            long long n,c,ans = 1;;
            int count;
        	while(~scanf("%lld%lld",&n,&c))
        	{
        		long long a[117];
        		for(int i = 0;i < n;i ++)
        		{
        			scanf("%lld",&a[i]);
        		}
        		ans = ((a[0]%c) * (a[1]%c))%c;
        		for(int i = 2;i < n; i++)
        		{	
        		    a[i] %= c;
        			ans *= a[i]; 
        			ans %= c;
        			a[i] = 0;
        		}
        		printf("%lld\n",ans);
        	}
        	return 0;
         } 
        
        • 0
          @ 2022-1-3 12:31:44
          #include<bits/stdc++.h>
          using namespace std;
          #define ll long long
          ll a[205];
          int main(){
          	ll n,c,ans;
          	while(scanf("%lld%lld",&n,&c)!=EOF){
          		for(int i=0;i<n;i++){
          				cin>>a[i];
          			}
          		for(int i=0;i<n;i++){
          			a[i]=a[i]%c;
          		}
          		ans=((a[0]%c)*(a[1]%c))%c;
          		for(int i=2;i<n;i++){
          			ans=((ans%c)*(a[i]%c))%c;
          		}
          		cout<<ans<<endl;
          	}
          	return 0;
          }
          
          • 1

          Information

          ID
          283
          Time
          1000ms
          Memory
          256MiB
          Difficulty
          7
          Tags
          # Submissions
          199
          Accepted
          45
          Uploaded By