by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
using namespace std;
int main()
{
char st[100];
long int a,i,j,ans,sum;
while(scanf("%s",st))
{
sum=0;
j=strlen(st);
for(i=0;i<j;i++)
{
a=st[i]-'0';
ans=a*(pow(2,j-i)-1);
sum+=ans;
}
if(sum==0) break;
cout<<sum<<endl;
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{ float h,m,ans,i,j;
while(scanf("%f:%f",&h,&m)==2)
{
if(h==0 and m==0) break;;
i=h*30+(m/60)*30;
j=m*6;
ans=(i-j);
if(ans<0)
ans=ans*(-1);
if (ans>180)
ans=360-ans;
printf("%.3lf\n",ans);
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
bool flag[20000005];
int List[100000],primes[100000];
int listSize,cnt;
using namespace std;
void sieve(int n)
{
cnt=0;
primes[cnt++] = 2;
for(int i=3; i<=n; i+=2)
{
if(flag[i] == 0)
{
primes[cnt++] = i;
if(i <= n/i)
{
for(int j=i*i; j<=n; j+=i*2)
flag[j] = 1;
}
}
}
return ;
}
void primeFactorize( int n )
{
listSize = 0;
for( int i = 0;i<cnt and primes[i]<=(int)sqrt(n);i++ )
{
if( n % primes[i] == 0 )
{
while( n % primes[i] == 0 )
{
n /= primes[i];
List[listSize] = primes[i];
listSize++;
}
}
}
if( n > 1 )
{
List[listSize] = n;
listSize++;
}
return ;
}
int main()
{
int n;
sieve(50000);
while(cin>>n) {
// scanf("%d", &n);
//printf(n < 0? "%d = -1 x " : "%d = ", n);
if(n == 0) break;
primeFactorize(fabs(n));
printf(n < 0? "%d = -1 x %d" : "%d = %d", n, List[0]);
for(int i = 1; i < listSize; i++)
printf(" x %d", List[i]);
printf("\n");
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,i,a[100],l=1,sum,move,av;
while(scanf("%d",&n)==1 )
{
if(n==0) break;
sum=0,move=0;;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
}
av=sum/n;
for(i=0;i<n;i++)
if(a[i]>av)
move=move+(a[i]-av);
printf("Set #%d\nThe minimum number of moves is %d.\n\n",l,move);
l++;
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
bool flag[20000005];
int primes[20000000];
int cnt;
void sieve(int n)
{
cnt=0;
primes[cnt++] = 2;
for(int i=3; i<=n; i+=2)
{
if(flag[i] == 0)
{
primes[cnt++] = i;
if(i <= n/i)
{
for(int j=i*i; j<=n; j+=i*2)
flag[j] = 1;
}
}
}
return ;
}
int main()
{
int n,i,j,count,l,c;
sieve(33000);
while(scanf("%d",&n)==1)
{
if(n==0)
break;
count=0;
c =0;
for(i=0; i<cnt; i++)
{
for(j=0; j<cnt; j++)
{
if(primes[i]==primes[j]&& primes[i]+primes[j]==n)
{
c++;
}
else if(primes[i]+primes[j]==n)
{
count++;
}
if(primes[i]+primes[j]>n)
break;
}
}
count = count/2 +c;
printf("%d\n",count);
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
long int a[10000];
int main()
{
long int n,i;
while(cin>>n)
{
if(n==0) break;
a[1]=1;
a[2]=2;
for(i=3;i<=n;i++)
{
a[i]=a[i-1]+a[i-2];
}
cout<<a[n]<<'\n';
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int n,sum;
while(scanf("%lld",&n)==1)
{
sum=(3*((n*n)/2+n)-6);
cout<<sum<<endl;
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
#define MAX 1000008
using namespace std;
bool flag[MAX];
int primes[MAX];
int cnt,a[2000];
void sieve(int n)
{
cnt=0;
primes[cnt++] = 2;
for(int i=3; i<=n; i+=2)
{
if(flag[i] == 0)
{
primes[cnt++] = i;
if(i <= n/i)
{
for(int j=i*i; j<=n; j+=i*2)
flag[j] = 1;
}
}
}
return ;
}
int main()
{
int n,u,l,pos,c,count,max,k,result,j,i;
sieve(MAX);
cin>>n;
while(n--)
{
pos=0;
cin>>l>>u;
for(int i=0;i<cnt;i++)
{
if(primes[i]>=l)
break;
pos++;
}
memset(a, 0, sizeof(a));
for(j=pos;j<cnt and primes[j+1]<=u;j++)
//a[primes[j+1] - primes[j]]++;
{
a[primes[j+1]-primes[j]]++;
}
count=0, max=0;
for(k=0; k<120; k++)
{
if(a[k]>max)
{
result=k;
max=a[k];
count=1;
}
else if(max==a[k])
count++;
}
if(count==1)
{
printf("The jumping champion is %d\n", result);
}
else
{
printf("No jumping champion\n");
}
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<cstring>
using namespace std;
bool flag[10001];
int primes[10001],result[10001];
int cnt,s;
void sieve(int n)
{
cnt=0;
primes[cnt++] = 2;
for(int i=3; i<=n; i+=2)
{
if(flag[i] == 0)
{
primes[cnt++] = i;
if(i <= n/i)
{
for(int j=i*i; j<=n; j+=i*2)
flag[j] = 1;
}
}
}
return ;
}
void value() {
//cout<<"p"<<N<<endl;
for (int i = 0; i < cnt; i++) {
s = 0;
for (int j = i; j < cnt; j++) {
s += primes[j];
if (s > 10001)
cout<<"s value"<<s<<endl;
continue;
result[s]++;
}
}
}
int main() {
int n;
sieve(10001);
value();
while (cin>>n and n>0) {
cout<<result[n]<<endl;
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
int tc,i,num,k,j, A,B,C,D,E,F,G,H,I,J;
cin>>tc;
while(tc--)
{
A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,J=0;
cin>>num;
for(i=1;i<=num;i++)
{
int s=i;
for( k=1 ; ; k++)
{
int mod=s%10;
if(mod==0)
A++;
if(mod==1)
B++;
if(mod==2)
C++;
if(mod==3)
D++;
if(mod==4)
E++;
if(mod==5)
F++;
if(mod==6)
G++;
if(mod==7)
H++;
if(mod==8)
I++;
if(mod==9)
J++;
s/=10;
if(s==0) break;
}
}
cout<<A<<" "<<B<<" "<<C<<" "<<D<<" "<<E<<" "<<F<<" "<<G<<" "<<H<<" "<<I<<" "<<J<<endl;
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
int n,i,score,sum,count;
cin>>n;
for(i=0;i<n;i++)
{
sum=0, count=0;
cin>>s;
for(int j=0;j<s.size();j++)
{
if(s[j]=='O')
{
count++;
sum+=count;
}
if(s[j]=='X')
{
count=0;
}
}
// sum+=count;
cout<<sum<<endl;
}
return 0;
}
by Jesmin Akther | Jan 11, 2019 | Problem Solving, UVa
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)==1 && n)
{
if(n==561 || n==1105 || n==1729 || n==2465 || n==2821 ||
n==6601 || n==8911 || n==10585 || n==15841 ||
n==29341 || n==41041 ||n== 46657|| n== 52633|| n==62745 ||
n==63973 || n==75361
)
printf("The number %d is a Carmichael number.\n",n);
else printf("%d is normal.\n",n);
}
return 0;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
double a0,an,a1,a,b,t,tc,n;
double c[3002];
int i;
cin>>t;
while(t--)
{
b=0;
cin>>n;
cin>>a0>>an;
if(n==0) printf("%0.2lf\n",an);
else{
for( i=0;i<n;i++)
{
cin>>c[i];
b+=((n-i)*c[i])*2;
}
a=((n*a0)+an);
a1=(a-b)/(n+1);
printf("%0.2lf\n",a1);
}
if(t) printf("\n");
}
return 0;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
long long int reverse(long long int n)
{
long long int sum=0,r;
while(n)
{
r=n%10;
sum=sum*10+r;
n=n/10;
}
return sum;
}
int main()
{
long long int t, sum, count;
int cse;
cin >> cse;
for (int i=0; i<cse; i++)
{
sum=0, count=0;
cin >> t;
while(reverse(t) != t)
{
count++;
t += reverse(t);
}
printf("%lld %lld\n",count,t);
}
return 0;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int get_count (int n);
int main()
{
int tc,i,j=0,n;
cin>>tc;
while(tc--)
{
scanf("%d",&n);
printf("%d ",get_count(n));
char s[50];
sprintf(s, "%d" ,n);
sscanf(s, "%x" ,&n);
printf("%d\n",get_count(n));
}
return 0;
}
int get_count (int n)
{
int c=0;
while(n != 0)
{
if ( n & 1)
c++;
n=n >> 1;
}
return c;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
long int a,b,x,y;
while(cin >> a >> b)
{
if (a == 0 && b == 0) break;
long int count=0,c=0;
while( a > 0 || b > 0)
{
count = (a%10 + b%10 + count)/10;
a/= 10;
b /= 10;
if (count) c++;
}
if (c == 0) printf ("No carry operation.\n");
else if(c==1)
printf("%ld carry operation.\n",c);
else
printf("%ld carry operations.\n",c);
}
return 0;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int a[502];
int main()
{
int i,j,t,n,sum;
cin>>t;
while(t--)
{
cin>>n;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
int v = a[n / 2];
sum = 0;
for (int j = 0; j < n; j++) {
sum += abs(v - a[j]);
}
cout<<sum<<endl;
}
return 0;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
char s[100000];
int main()
{
long int i,L;
while(gets(s))
{
L=strlen(s);
for(i=0;i<L;i++)
{
switch(s[i])
{
case 'W':
printf("Q"); break;
case 'E':
printf("W"); break;
case 'R':
printf("E"); break;
case 'T':
printf("R"); break;
case 'Y':
printf("T"); break;
case 'U':
printf("Y"); break;
case 'I':
printf("U"); break;
case 'O':
printf("I"); break;
case 'P':
printf("O"); break;
case 'S':
printf("A"); break;
case 'D':
printf("S"); break;
case 'F':
printf("D"); break;
case 'G':
printf("F"); break;
case 'H':
printf("G"); break;
case 'J':
printf("H"); break;
case 'K':
printf("J"); break;
case 'L':
printf("K"); break;
case 'X':
printf("Z"); break;
case 'C':
printf("X"); break;
case 'V':
printf("C"); break;
case 'B':
printf("V"); break;
case 'N':
printf("B"); break;
case 'M':
printf("N"); break;
case '2':
printf("1"); break;
case '3':
printf("2"); break;
case '4':
printf("3"); break;
case '5':
printf("4"); break;
case '6':
printf("5"); break;
case '7':
printf("6"); break;
case '8':
printf("7"); break;
case '9':
printf("8"); break;
case '0':
printf("9"); break;
case '-':
printf("0"); break;
case '=':
printf("-"); break;
case '[':
printf("P"); break;
case ']':
printf("["); break;
case '\\':
printf("]"); break;
case ';':
printf("L"); break;
case '1':
printf("`"); break;
case ',':
printf("M"); break;
case '.':
printf(","); break;
case '/':
printf("."); break;
case ' ':
printf(" "); break;
default:
printf(";"); break;
}
}
printf("\n");
}
return 0;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <vector>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int input,value;
vector<int>myvector;
if(myvector.empty())
while(cin>>input)
{
myvector.push_back(input);
sort(myvector.begin(),myvector.end());
if(!(myvector.empty()))
if(myvector.size() % 2 == 1) {
cout<<myvector[myvector.size() / 2]<<endl;
}
else
cout<<( myvector[myvector.size() / 2] + myvector[myvector.size() / 2 - 1] ) / 2<<endl;
}
return 0;
}
by Jesmin Akther | Jan 10, 2019 | Problem Solving, UVa
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int n;
while(cin>>n)
{
if(n==0) break;
long long int n1=sqrt(n);
if((n1*n1)==n)
{
cout<<"yes"<<endl;
}
else
cout<<"no"<<endl;
}
return 0;
}