Posts

Showing posts from August, 2022

Fashion Shows Problem Spoj solution

 #include <iostream> #include<algorithm> using namespace std; int main() { int t; cin>>t; while(t--){ int n,i,s=0; cin>>n; int a[n],b[n]; for(i=0;i<n;i++){ cin>>a[i]; } for(i=0;i<n;i++){ cin>>b[i]; } sort(a,a+n); sort(b,b+n); for(i=0;i<n;i++){ s+=a[i]*b[i]; } cout<<s<<endl; } return 0; }

The Last Digit problem Spoj Solution

 #include <iostream> using namespace std; typedef long long l; int main(){ l t; cin>>t; while(t--){ l a,b,r1,r2; cin>>a>>b; r1=a%10; r2=b%4; if(a==0){ cout<<"0"<<endl; } else if(b==0){ cout<<"1"<<endl; } else if(r1==1 || r1== 5 || r1==6 || r1==0){ cout<<r1<<endl; } else{ if(r2==1){ cout<<r1%10<<endl; } else if(r2==2){ cout<<(r1*r1)%10<<endl; } else if(r2==3){ cout<<(r1*r1*r1)%10<<endl; } else  cout<<(r1*r1*r1*r1)%10<<endl; } } }

Life, The Universe And Everything problem Spoj Solution

 #include <iostream> using namespace std; int main() { int n ; while(1) { cin>>n; if(n==42) { break; }      cout<<n<<endl; } return 0; }

Prime Generator problem Spoj Solution

 #include<iostream> #include<cmath> using namespace std; typedef long long l; bool prime(l ); int main(){ l t; cin>>t; while(t--){ l n,m,i; cin>>m>>n; for(i=m;i<=n;i++){   if(prime(i)){ cout<<i<<endl; } } cout<<endl; } } bool prime(l a){ if(a==1) return 0; for(l i=2;i*i<=a;i++){ if(a%i==0) return 0; } return 1; }

Factorials problem spoj Solution

In order to find factorial of n and number zeros at the end of factorial decimal, i simply find prime factors (5) ,and find the count then the count is our required answer.  #include <iostream> using namespace std; typedef long long l; int zero(l ); int main() { l t; cin>>t; while(t--){ l n; cin>>n; cout<<zero(n)<<endl; } return 0; } int zero(l n){ l c=0; if(n<0) return 0; for(l i=5;n/i>=1;i=i*5){ c+=n/i; } return c; }

Small Factorials Spoj Solution(using python)

For this problem, when we use the languages like c++ , c it is going to show due to time or time limit exceded ,for getting solution i used python .  t=int(input()) while(t): n=int(input()) fact=1 for i in range(1,n+1): fact=fact*i print(fact) t=t-1 If you have any doubts comment below ๐Ÿ‘‡

What's Next Spoj Problem Solution

 #include <iostream> using namespace std; typedef long long l; int main() {     l a1,a2,a3;     cin>>a1>>a2>>a3; do{     if((a2-a1)==(a3-a2)){ cout<<"AP"<<" "<<(a3+(a3-a2))<<endl; } else{ cout<<"GP"<<" "<<(a3)*a2/a1<<endl; } cin>>a1>>a2>>a3; }while(a1 || a2 || a3);     return 0; } ๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€ If you have any doubts comment below๐Ÿ‘‡

Adding Reversed Numbers Spoj Solutions

 #include <iostream> using namespace std; int main() { int t; cin>>t; while(t--){ long long int n,m,rev=0,rev1=0,n1,m1,s=0,r; cin>>n>>m; n1=n;m1=m; while(n>0){ rev=rev*10+n%10; n/=10; } while(m>0){ rev1=rev1*10+m%10; m/=10; } s=rev+rev1; long long int srev=0;     while(s>0){ srev=srev*10+s%10; s/=10; } cout<<srev<<endl; } return 0; } ๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€ If you have any doubts comment below๐Ÿ‘‡
  #include <iostream> #include <cstdlib> using namespace std ; int main (){ int n , i , j , s = 0 , s1 = 0 , l , m ; for ( i = 1 ; i <= 5 ; i ++){ for ( j = 1 ; j <= 5 ; j ++){ cin >> n ; if ( n == 1 ){ l = i ; m = j ; } } } s = abs ( 3 - l ); s1 = abs ( 3 - m ); cout << s + s1 ; } Input 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 3 Answer 3  ๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€ If you have any doutbts comment in the below๐Ÿ‘‡

Beautifull Matrix Code Forces Solution

#include <iostream> #include <cstdlib> using namespace std ; int main (){ int n , i , j , s = 0 , s1 = 0 , l , m ; for ( i = 1 ; i <= 5 ; i ++){ for ( j = 1 ; j <= 5 ; j ++){ cin >> n ; if ( n == 1 ){ l = i ; m = j ; } } } s = abs ( 3 - l ); s1 = abs ( 3 - m ); cout << s + s1 ; } Input 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Output 3 Answer 3  ๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€ If you have any doutbts comment in the below๐Ÿ‘‡ Comment :