AP- Complete the series Spoj solution(AP2)

AP2

#include<stdio.h>
#define LL long long
int main()
{
 int t;
 scanf("%d",&t);
 while(t--){
  LL a,b,c,i,j;
  scanf("%lld%lld%lld",&a,&b,&c);
  LL n=(c*2)/(a+b);
  LL d=(b-a)/(n-5);
  LL m=a-2*d;
  printf("%lld\n",n);
  for(i=m,j=0;j<n;i+=d,j++){
   printf("%lld ",i);
  }
  printf("\n");
 }
 return 0;
}

Spoj Problem Candy 3(CANDY3)

CANDY3

#include<iostream>
using namespace std;
int main()
{
int t, n, i;
long long  s, a;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
s = 0;
for(i=0;i<n;i++)
{
scanf("%lld",&a);
s += a;
if(s >= n) s %= n;
}
if(s == 0) printf("YES\n");
else printf("NO\n");
}
return 0;
}

Spoj Problem Solution ololo(OLOLO)

OLOLO

#include<iostream>
using namespace std;
int main()
{
    int n,i;
    scanf("%d",&n);
    long long int arr[500001];
    for(i=0;i<n;i++)
        scanf("%lld",&arr[i]);
    long long int a,ans;
    a=arr[0];
    for(i=1;i<n;i++)
    {
        ans=a^arr[i];
        a=ans;
    }
    printf("%lld\n",ans);
    return 0;
}

Spoj Problem solution for Dota Heros(DOTAA)

DOTAA

#include<iostream>
using namespace std;
int main()
{
int t,n,m,d,h;
scanf("%d",&t);

while(t--)
{
int count=0;
scanf("%d %d %d",&n,&m,&d);
while(n--)
{
scanf("%d",&h);
if(h>d)
{
while(h>0)
{
    h=h-d;
    count++;
   
}
count--;
}
}
if(count<m)
printf("NO\n");
else
printf("YES\n");
}
return(0);
}

Last digit Re Visited(LASTDIG2)

LASTDIG2

#include<stdio.h>
#include<string.h>
int main()
{
char str[1005];
unsigned long long int b,a,ans,len,t;
scanf("%llu",&t);
while(t--){
scanf("%s",str);
scanf("%llu",&b);
 len=strlen(str);
a=str[len-1]-'0';
if(b==0&&a!=0) ans=1;
else{
if(a==0){ ans=0; goto end;}
if(a==5) {ans=5; goto end;}
switch(b%4){
case 0: ans=a%2!=0? 1:6;
break;
case 1: ans=a;
break;
case 2: ans=a*a%10;
break;
default : ans=a*a*a%10;
break;
}
}
end :
printf("%llu\n",ans);
}
return 0;
}

problem solution for last digit(LASTDIG)

 LASTDIG

#include<stdio.h>
#include<string.h>
int main()
{
char str[1005];
unsigned long long int b,a,ans,len,t;
scanf("%llu",&t);
while(t--){
scanf("%s",str);
scanf("%llu",&b);
 len=strlen(str);
a=str[len-1]-'0';
if(b==0&&a!=0) ans=1;
else{
if(a==0){ ans=0; goto end;}
if(a==5) {ans=5; goto end;}
switch(b%4){
case 0: ans=a%2!=0? 1:6;
break;
case 1: ans=a;
break;
case 2: ans=a*a%10;
break;
default : ans=a*a*a%10;
break;
}
}
end :
printf("%llu\n",ans);
}
return 0;
}

Triple fat ladies(EIGHT)

problem link:EIGHT


#include<stdio.h>
int main()
{
    int te;
    scanf("%d",&te);
    while(te--)
    {
        long long n;
        scanf("%lld",&n);
        long long a;
        a=192+(n-1)*250;
        printf("%lld\n",a);
    }
    return (0);
}




 

Amusing number spoj problem solution(TSHOW1)

TSHOW1

#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
    int t;
    long long int num,temp,n,i,j,ans,k,rem;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld",&num);
        temp=0,n=0;
        while(temp<num)
      
        {
            n=n+1;
            temp=pow(2,n+1)-2;
           
        }
        temp=pow(2,n)-2;
       
        ans=num-temp-1;
        char str[100000];
        int k=-1;

       
        while(ans>0)
        {
            rem=ans%2;
            k=k+1;
            str[k]=rem+'0';
            ans=ans/2;
        }
        j=n-k-1;
        for(i=1;i<=j;i++)
            printf("5");

       
        for(i=k;i>=0;i--){
            if(str[i]=='0')
                printf("5");
            else
                printf("6");
        }
        printf("\n");
    }
    return 0;
}

manku word spoj solution(MAY99_2)

MAY99_2

#include <cstdio>
 #include <cmath>
 #include <string>
  #include <iostream>
   using namespace std;

int nchar( long long int a)

 {
  int ctr = 0;
   long long int n = 0;
    while( n < a)
     {
      n += pow(5,++ctr);
      
       }
        return ctr;
        }

int main()
 {
  int t;
   scanf("%d",&t);
    string m ="manku";
     long long int n;
      while(t--)
       {
        string s = "";
         scanf("%lld",&n);
          int g = nchar(n);
           for( int i = 0; i < g ;i++)
            {
             int j = n % 5;
              if( j == 0)
               j=5;
                s = m.substr(j-1,1) + s ;
                 if(n%5 ==0)
                 n = n/5 -1;
                  else
                   n = n / 5;
                    }
                    cout <<s<< endl;
                    
                     }
                      return 0;
                       }
                      
                      
                      
                      
                      

spoj marbles problem solution(MARBLES)

MARBLES


#include<iostream>
#include<stdlib.h>

using namespace std;

class B{
   long long int i,j,k,N,K,temp;
  public:
    void input(){
         cin>>N>>K;
         N--;
         K--;
         
    }
    void calc(){
       i=N-K;
       if(N==K||K==0) {tmp=1;}
       else if(K==1){tmp=N;}
       else  if(i>K)
       {
          j=1;
          tmp=1;
          
          while(j<=K)
          {
            if(N%j==0)
            tmp=tmp*(N/j);
            else if(tmp%j==0)
             tmp=N*(tmp/j);
            else tmp=(N*tmp)/j;
             
            j++;
            N--;
         
          }
        }
        else if(i<=K)
        {     
           j=1;
           tmp=1;
          while(j<=i)
          {
            if(N%j==0)
            tmp=tmp*(N/j);
            else if(tmp%j==0)
            tmp=N*(tmp/j);
            else tmp=(N*tmp)/j;
            j++;
            N--;
           }
         }
       }
      void output(){
         cout<<tmp<<endl;
      }
};

int main()
{
  B a;
  int T;
  cin>>T;
  while(T--){
    a.input();
    a.calc();
    a.output();
  }

return 0;
}

Army Strength spoj problem solution(ARMY)

 ARMY


#include<stdio.h>
int main()
{
 int t;
 scanf("%d",&t);
 int i;
 int j;
 int ng;
 int nm;
 int m1;
 int m2;
 for(i=0;i<t;i++) {
  scanf("%d",&ng);
  scanf("%d",&nm);
  int g[ng];
  int m[nm];
  for(j=0;j<ng;j++) {
   scanf("%d",&g[j]);
  }
  for(j=0;j<nm;j++) {
   scanf("%d",&m[j]);
  }
  m1=g[0];
  m2=m[0];
  for(j=1;j<ng;j++) {
   if(m1<g[j])
   m1=g[j];
  }
  for(j=1;j<nm;j++) {
   if(m2<m[j])
   m2=m[j];
  }
  if(m1>=m2)
   printf("Godzilla\n");
  else if(m1<m2)
   printf("MechaGodzilla\n");
  else
   printf("u");
 }
 return 0;
}

Build A fence(BUILD)

spoj solution of Build A fence


#include<stdio.h>
int main()
{
        double a;
        double pie=3.141592653589793238462643383279;
        scanf("%lf",&a);
        while(a!=0)
        {
        double r=a/pie;
        double area=pie*r*r/2.0;
        printf("%.2lf\n",area);
        scanf("%lf",&a);
        }
        return 0;
}

spoj reversed no(ADDREV)

ADDREV spoj problem
#include<iostream>
using namespace std;
int reverse(int n);
int add(int n, int m);
int main()
{
 int a,b,t;
 cin>>t;
 while(t--)
 {
    cin>>a>>b;
  
    int e=add(reverse(a),reverse(b));
   
    cout<<reverse(e)<<endl;
   
 }
 return 0;
}

 int reverse(int n)
 {    int sum=0;
     while(n>0)
     {
     int r=n%10;
   
     sum=sum*10+r;
     n=n/10;
     }
    
     return sum;
 }
 int add(int n,int m)
 {
     return (n+m);
 }

   


Life and Universe(TEST)

spoj life and universe

#include<iostream>
using namespace std;
int main()
{
int a;
cin>>a;
while(a!=42)
{
    cout<<a<<"\n";
     cin>>a;
   
}
return 0;
}