Skip to main content

Posts

Showing posts with the label Mathematics

URI Problem 2232 Solution Pascal's Triangle - URI Online Judge Solution

URI Online Judge Solution 2143 Pascal's Triangle   Using Python Programming Language.   Pascal's Triangle (also known as Tartaglia Triangle in some countries), is an infinite numeric triangle formed by binomial numbers  , where  n  represents the row number and  k  represents the column number (0-indexed). The triangle was discovered by the chinese mathematician Yang Hui, and 500 years later, many of its properties was studied by Blaise Pascal. Each number in Pascal's Triangle is equal to the sum of the number immediately above it and its predecessor. David, the mastermind of your competitive programming team, found that the sum of the  i th  row of the Pascal's Triangle is  2 i . Now, he wants to find the sum of the first N rows of the triangle. However, he thinks this problem is too easy and does not deserve his attention (he decided to try to solve a problem about bipartite graphs instead, a much harder topic), thus, you are the one w...

URI Problem 1279 Solution Leap Year or Not Leap Year and … - URI Online Judge Solution

URI Online Judge Solution 1279 Solution Leap Year or Not Leap Year and …   Using Python Programming Language. The ancient race of Gulamatu is very advanced in their year calculation scheme. They understand what leap year is (A year that is divisible by 4 and not divisible by 100 with the exception that years that are divisible by 400 are also leap year.) and they have also similar festival years. One is the Huluculu festival (happens on years divisible by 15) and the Bulukulu festival (Happens on years divisible by 55 provided that is also a leap year). Given an year you will have to state what properties these years have. If the year is not leap year nor festival year, then print the line 'This is an ordinary year.' The order of printing (if present) the properties is leap year-->huluculu-->bulukulu. Input Input will contain several years as input. Each year will be in separate lines. Input is terminated by end of file. All the years will not be less than 2000 (to avoid...

URI Problem 1221 Solution Fast Prime Number - URI Online Judge Solution

URI Online Judge Solution 1221 Fast Prime Number  Using C++, Python Programming Language. Mary knows that a Prime Number is a number that is divisible only by 1 (one) and by itself. For example the number 7 is Prime, because it can be divided only by 1 and by 7. So she asked you to write a program that reads many numbers ​​and inform if each one of these numbers are prime or not. But Patience is not one of the virtues of Mariazinha, so she wants that the execution of all test cases (instances) created by herself happen at the maximum in one second, because she hates waiting :>). Input The first input line contains an integer N (1 ≤ N ≤ 200), corresponding to the number of test cases. Follow N lines, each one containig one integer number X (1 < X < 231) that can be or not a prime number Output For each test case output the message “Prime” or “Not Prime” according to the to following example. Sample Input Sample Output 3 123321 123 103 Not Prime Not Prime Prime Solution Usin...

URI Problem 1214 Solution Above Average - URI Online Judge Solution

URI Online Judge Solution  1214 Above Average  Using C, Python Programming Language. It is said that 90% of frosh expect to be above average in their class. You are to provide a reality check. Input The input contains many test cases. The first line of standard input contains an integer C, the number of test cases. C data sets follow. Each data set begins with an integer, N, the number of people in the class (1 ≤ N ≤ 1000). N integers follow, separated by spaces or newlines, each giving the final grade (an integer between 0 and 100) of a student in the class. Output For each case you are to output a line giving the percentage of students whose grade is above average, rounded to 3 decimal places. Sample Input Sample Output 5 5 50 50 70 80 100 7 100 95 90 80 70 60 50 3 70 90 80 3 70 90 81 9 100 99 98 97 96 95 94 93 91 40.000% 57.143% 33.333% 66.667% 55.556% Solution Using C: #include<stdio.h> int main() { int T; scanf( "%d" , &T); while (T--) { ...

URI Problem 1212 Solution Primary Arithmetic - URI Online Judge Solution

URI Online Judge Solution  1212 Primary Arithmetic  Using C, Python Programming Language. Children are taught to add multi-digit numbers from right-to-left one digit at a time. Many find the "carry" operation - in which a 1 is carried from one digit position to be added to the next - to be a significant challenge. Your job is to count the number of carry operations for each of a set of addition problems so that educators may assess their difficulty. Input Each line of input contains two unsigned integers less than 10 digits. The last line of input contains 0 0. Output For each line of input except the last you should compute and print the number of carry operations that would result from adding the two numbers, in the format shown below. Sample Input Sample Output 123 456 555 555 123 594 0 0 No carry operation. 3 carry operations. 1 carry operation. Solution Using C: #include<stdio.h> int main() { long x , y , c , ans; while ( 1 ) { c = ans = 0 ; ...

URI Problem 1197 Solution Back to High School Physics - URI Online Judge Solution

URI Online Judge Solution 1197 Back to High School Physics   Using C++, Python Programming Language. A particle has initial velocity and constant 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). The end of the input is determined by EOF. Output For each line of input print a single integer in one line denoting the displacement in double of that time. Input Sample Output Sample 0 0 5 12 0 120 Solution Using C++: #include<iostream> using namespace std; int main() {     int v,t;     while(cin>>v>>t)     {         cout<<v*t*2<<endl;     }     return 0; }

URI Problem 1170 Solution Blobs - URI Online Judge Solution

  URI Online Judge Solution 1170 Blobs Using C, Python Programming Language. On the planet Alpha lives the creature Blobs, that eats just half of its supply of food available all day. Write an algorithm that reads the initial capacity of the food supply (in Kg), and calculate how many days will pass before Blobs eat all this supply until left a kg or less. Input The first line of the input contains a single integer N (1 ≤ N ≤ 1000), indicating the number of test cases. Each test case contains a single floating-point number X (1 ≤ X ≤ 1000), indicating the amount of food available for Blobs. Output For each test case, print one line containing the number of days that blobs will take to eat all their food supply, followed by the word "dias" that means days in portuguese. Input Sample Output Sample 3 40.0 200.0 300.0 6 dias 8 dias 9 dias Solution Using Python: T = int ( input ()) D = 0 while T> 0 : N = float ( input ()) while True : N = N/ 2 if N<= ...

URI Problem 1161 Solution Factorial Sum - URI Online Judge Solution

  URI Online Judge Solution 1161 Factorial Sum Using C, Python Programming Language. Read two numbers M and N indefinitely. Calculate and write the sum of their factorial. Be carefull, because the result can have more than 15 digits. Input The input file contains many test cases. Each test case contains two integer numbers M (0 ≤ M ≤ 20) and N (0 ≤ N ≤ 20). The end of file is determined by eof. Output For each test case in the input your program must print a single line, containing a number that is the sum of the both factorial (M and N). Input Sample Output Sample 4 4 0 0 0 2 48 2 3 Solution Using C: #include<stdio.h> unsigned long long Fact(int x) {     if(x==0) return 1;     unsigned long long n=1;     while(x>0)     {         n = n*x;         x--;     }     return n; } int main() {     int m,n;     while(scanf("%d%d",&m,&n) != EOF)   ...

URI Online Judge Solution 1028 Collectable Cards

URI Online Judge Solution 1028 Collectable Cards using C Programming Language. Richard and Vicent are crazy about football collectable cards. In their spare time, they arrange a way of playing some game involving such cards. Both also have the habit of exchanging the repeated cards with their friends, and one day they thought about a different game. They called all their friends and proposed the following: with the cards in hand, each one tried to make an exchange with his closest friend following this simple rule: each one must count how many cards he owned. After this, they had to split these cards into stacks, all of it with the same size, as large as it was possible for both players. Then, each one choose one of the friend's card stacks to receive. For example, if Richard and Vincent would change the cards with respectively 8 and 12 cards each, both must put his cards in stacks of four cards (Richard would have two stacks and Vincent had three stacks), and both choose...