Posts

Find Digits

Find Digits Given an integer,  , traverse its digits ( 1 , 2 ,..., n ) and determine how many digits evenly divide   (i.e.: count the number of times   divided by each digit  i  has a remainder of  ). Print the number of evenly divisible digits. Note:  Each digit is considered to be unique, so each occurrence of the same evenly divisible digit should be counted (i.e.: for  , the answer is  ). Solution--- #include<stdio.h> int main() {         int t,i,a,d,c,count,j;         scanf("%d",&t);         for(i=0;i<t;i++)         {       count=0;                 scanf("%d",&a);                 c=a;                 while(a!=0){               ...

Save the Prisoner!

Save the Prisoner! A jail has   prisoners, and each prisoner has a unique id number,  , ranging from   to  . There are   sweets that must be distributed to the prisoners. The jailer decides the fairest way to do this is by sitting the prisoners down in a circle (ordered by ascending  ), and then, starting with some random  , distribute one candy at a time to each sequentially numbered prisoner until all   candies are distributed. For example, if the jailer picks prisoner  , then his distribution order would be   until all   sweets are distributed. But wait—there's a catch—the very last sweet is poisoned! Can you find and print the ID number of the last prisoner to receive a sweet so he can be warned? --Solution--- #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() {     /* Enter your code here. Read...

Angry Professor

#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> Angry Professor  A Discrete Mathematics professor has a class of   students. Frustrated with their lack of discipline, he decides to cancel class if fewer than   students are present when class starts. Given the arrival time of each student, determine if the class is canceled. Solution--- int main() {    int t,n,k,a,r,j;     scanf("%d",&t);     int i;     for(i=0;i<t;i++)         {r=0;         scanf("%d%d",&n,&k);         for(j=0;j<n;j++){                    scanf("%d",&a);             if(a<=0){                 r++;}                     ...

Utopian Tree

Utopian Tree The Utopian Tree goes through  2  cycles of growth every year. Each spring, it  doubles  in height. Each summer, its height increases by  1  meter. Laura plants a Utopian Tree sapling with a height of  1  meter at the onset of spring. How tall will her tree be after   growth cycles? ----Solution-- import sys T = int(sys.stdin.readline()) for _ in range(T):     N = int(sys.stdin.readline())     height = 1              for i in range(N):         if i % 2 == 0:             height *= 2         else:             height += 1                  print(height)
HackeRank Problem John Watson performs an operation called a  right circular rotation  on an array of integers,  . After performing one  right circular rotation  operation, the array is transformed from   to  . Watson performs this operation   times. To test Sherlock's ability to identify the current element at a particular position in the rotated array, Watson asks   queries, where each query consists of a single integer,  , for which you must print the element at index   in the rotated array (i.e., the value of  ). -----Solution---- #include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #include <limits.h> #include <stdbool.h> int main(){     int n,k,q     scanf("%d %d %d",&n,&k,&q);     int *a = malloc(sizeof(int) * n);     for(int a_i = 0; a_i ...