Showing posts with label Codeforces. Show all posts
Showing posts with label Codeforces. Show all posts

Friday, August 12, 2022

Codeforces 750A - New Year and Hurry

Problem Link - https://codeforces.com/contest/750/problem/A

Editorial

Do you see what is produced by the following piece of code?

int total = 0;
for(int i = 1; i <= n; ++i) {
	total += 5 * i;
	printf("%d\n", total);
}

We iterate over problems (a variable i denotes the index of problem) and in a variable total we store the total time needed to solve them. The code above would print numbers 5, 15, 30, 50, ... — the i-th of these numbers is the number of minutes the hero would spend to solve easiest i problems.

Inside the loop you should also check if there is enough time to make it to the party, i.e. check if total + k <= 240.

Solution

        
    #include<bits/stdc++.h>
    using namespace std;

    int main()
    {  
    int n,k; int count=0; int sum=0;
    cin>>n>>k;

    for(int i=1; i<=n; i++)
    {
        sum += 5*i;  
        if(sum>240-k) break;
        count +=1;
    }
    cout<<count<<endl;
    return 0;
    }

Monday, April 03, 2017

Codeforces 556A ( Case of Zeros and Ones )




Codeforces 556A
Case of Zeros and Ones



Problem Link:
http://codeforces.com/problemset/problem/556/A

Codeforces 791A ( Bear and Big Brother )


Codeforces 791A 
( Bear and Big Brother )



Problem Link:
http://codeforces.com/problemset/problem/791/A
Solution : 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,i,j,cnt;
    cin>>a>>b;
    cnt=0;
    for(i=1;; i++)
    {
            a=a*3;
            b=b*2;
            cnt++;

        if(a>b)
        {
            break;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Sunday, April 02, 2017

Codeforces Problem 762A (K-th-divisor)

Codeforces Problem 762A 
(K-th-divisor)


Problem link : 
http://codeforces.com/problemset/problem/762/A

You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.
Divisor of n is any such natural number, that n can be divided by it without remainder.
Input
The first line contains two integers n and k (1 ≤ n ≤ 10151 ≤ k ≤ 109).
Output

Codeforces 749A (Bachgold Problem)


Codeforces 749A (Bachgold Problem)



time limit per test-
1 second

memory limit per test-
256 megabytes

input-
standard input

output-
standard output
Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and k.