#include <stdio.h> #include<iostream> #include<math.h> using namespace std; int primes[]={2,3 ,5, 7, 11, 13, 17, 19, 23 ,29 ,31 ,37, 41, 43, 47 ,53 ,59 ,61, 67, 71, 73, 79, 83, 89, 97 ,101, 103, 107, 109, 113, 127 ,131, 137, 139, 149, 151 ,157 ,163,...
UVA Problem 575 – Skew Binary Solution
#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; }...
UVA Problem 579( Clock Hands) Solution
#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); }...
UVA Problem 583( Prime Factors ) Solution
#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...
UVA Problem(Box of Bricks solution) 591 Solution
#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)...
UVA Problem( Goldbach’s Conjecture (II) ) 686 Solution
#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...
UVA Problem( Brick Wall Patterns) 900 Solution
#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; }...
UVA Problem(Joana and the Odd Numbers) 913 Solution
#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; }
UVA Problem( Jumping Champion) 914 Solution
#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;...
UVA Problem(Sum of Consecutive Prime Numbers) 1210 Solution
#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;...
UVA Problem(Digit Counting) 1225 Solution
#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)...
UVA Problem(Score) 1585 Solution
#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; } }...
UVA Problem( Carmichael Numbers) 10006 Solution
#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||...
UVA Problem 10014 Solution
#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];...
UVA Problem 10018 Solution
#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;...
UVA Problem 10019 Solution
#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));...
UVA Problem 10035 Solution
#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...
UVA Problem 10041 Solution
#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...
UVA Problem 10082 Solution
#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");...
UVA Problem 10107 Solution
#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) {...
Java’s Next Leap: Exploring Project Valhalla & JEP 401 (Value Classes) Early Access
Discover Project Valhalla’s impact on Java performance! Explore JEP 401 (Value Classes & Objects) and learn how to try the new Early Access build for a faster, leaner JVM.
Navigating the AI Frontier: Why Staying Updated on Artificial Intelligence News is Crucial
The world of AI is evolving at lightning speed. Discover why keeping up with the latest Artificial Intelligence news and trends is essential for everyone.
Master Your IELTS Journey: Latest News, Updates & Essential Resources
Stay ahead in your IELTS preparation! Discover the latest test changes, essential resources, and expert tips to achieve your target score with confidence.
Decoding Tomorrow: Exploring the Latest Technology Breakthroughs and Scientific Research
Dive into the forefront of innovation with insights into nanotechnology, biotechnology, green tech, and other groundbreaking scientific research shaping our future.




