Saturday, December 5, 2015

Uri problem 1164

Description:

Perfect Number

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
In mathematics, a perfect number is an integer for which the sum of all its own positive divisors (excluding itself) is equal to the number itself. For example the number 6 is perfect, because 1+2+3 is equal to 6. Your task is to write a program that read integer numbers and print a message informing if these numbers are perfect or are not perfect.

Input

The input contains several test cases. The first contains the number of test cases (1 ≤ N ≤ 100). Each of the following N lines contain an integer X (1 ≤ X ≤ 108), that can be or not a perfect number.

Output

For each test case output the message “eh perfeito” (is perfect) or “nao eh perfeito” (X isn't perfect) according with to above specification.
Sample InputSample Output
3
6
5
28
6 eh perfeito
5 nao eh perfeito
28 eh perfeito
Solution:

#include<stdio.h>
int main()
{
    int x , i, T, sum=0;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&x);
        for(i=1; i<x; i++){
            if(x%i==0){
                sum+=i;
            }
        }
        if(sum==x)
            printf("%d eh perfeito\n",x);
        else
            printf("%d nao eh perfeito\n",x);
        sum=0;
    }

    return 0;
}

Friday, December 4, 2015

Codeforces 4A - Watermelon

A. Watermelon
time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
Input
The first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys.
Output
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
Sample test(s)
input
8
output
YES
Note
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
Solution:
#include<stdio.h>
int main()
{
    int w;
    while(scanf("%d",&w)==1){
        if(w%2==0 && w!=2)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

Codeforces 546A - Soldier and Bananas

A. Soldier and Bananas
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).
He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?
Input
The first line contains three positive integers k, n, w (1  ≤  k, w  ≤  10000 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Sample test(s)
input
3 17 4
output
13
Solution:
#include<stdio.h>
int main()
{
    int k, n, w,sum=0,i=1; 
    scanf("%d %d %d",&k,&n,&w);
    for(;0< w;w--,i++)
    {
        sum=sum+(k*i);
    }
    if(sum>n)printf("%d\n",sum-n); 
    else printf("0\n"); 
 
    return 0;
}

UVA problem : 10071 - Back to High School Physics


Description: A particle has initial velocity and acceleration. If its velocity after certain time is v then what will its displacement be in twice of that time? Input The input will contain two integers in each line. Each line makes one set of input. These two integers denote the value of v (−100 ≤ v ≤ 100) and t (0 ≤ t ≤ 200) (t means at the time the particle gains that velocity) Output For each line of input print a single integer in one line denoting the displacement in double of that time.

 Sample Input :

 0 0 

5 12
Sample Output
 0
120
Solution:

#include<stdio.h>

int main()
{
    int v , t;
    while(scanf("%d %d",&v,&t) == 2){
        printf("%d\n",2*v*t);
    }

    return 0;
}

Uri problem 1001 solve


Descriptions :

Extremely Basic

Read 2 variables, named A and B and make the sum of these two variables, assigning its result to the variable X. Print X as shown below. Print endline after the result otherwise you will get “Presentation Error”.

Input

The input file will contain 2 integer numbers.

Output

Print X according to the following example, with a blank space before and after the equal signal.
Sample InputsSample Outputs
10
9
X = 19
-10
4
X = -6
15
-7
X = 8

Solution:

#include <stdio.h>
  
int main() {
  
    int A , B , X;
    scanf("%d %d",&A , &B);
    X= A + B;
    printf("X = %d\n", X);
  
    return 0;
}

Wednesday, December 2, 2015

Uri problem 1079 solve

Weighted Averages

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Read an integer N, which represents the number of following test cases. Each test case consists of three floating-point numbers, each one with one digit after the decimal point. Print the weighted average for each of these sets of three numbers, considering that the first number has weight 2, the second number has weight 3 and the third number has weight 5.

Input

The input file contains an integer number N in the first line. Each following line is a test case with three float-point numbers, each one with one digit after the decimal point.

Output

For each test case, print the weighted average according with below example.
Sample InputSample Output
3
6.5 4.3 6.2
5.1 4.2 8.1
8.0 9.0 10.0
5.7
6.3
9.3

Solution:

#include<stdio.h>
int main()
{
   double x , T, num[3], media;
   scanf("%lf",&T);
   while(T--){
    scanf("%lf %lf %lf",&num[0],&num[1],&num[2]);
    media=((num[0]*2)+(num[1]*3)+(num[2]*5))/(2+3+5);
    printf("%.1lf\n",media);
    num[0]=0;
    num[1]=0;
    num[2]=0;
    media=0;
   }
    return 0;
}