Posts

Showing posts from July, 2020

80A - Panoramix's Prediction

80A - Panoramix's Prediction #include<iostream> using namespace std; int primechecker(int n){  int i;  bool f =true;  for(int i=2;i<n ;i++)     if(n%i==0) {  f = false;  }    if(f) return 1;    else return 0;     } int main()   {    int n,m,result;    cin>>n>>m;     for(int i=0;i<50;i++){    n++;    if(primechecker(n)==1) { result = n; break;}    }    if(result==m) cout<<"YES";    else cout<<"NO";    }

104A - Blackjack

104A - Blackjack #include < bits / stdc ++. h > using namespace std ; int main (){ int n ; cin >> n ; int d = n - 10 ; if ( d == 10 ) cout << 15 ; else if ( d == 0 ) cout << 0 ; else if ( d > 11 or n <= 10 ) cout << 0 ; else if ( d <= 11 ) cout << 4 ; }

609A - A. USB Flash Drives

609A -   USB Flash Drives #include < bits / stdc ++. h > using namespace std ; int main (){ int n , m ; cin >> n >> m ; int a [ n ]; for ( int i = 0 ; i < n ; i ++) cin >> a [ i ]; sort ( a , a + n ); reverse ( a , a + n ); int s = 0 ; int i = 0 , ans = 0 ; while ( 1 ){ s = s + a [ i ];   ans ++; i ++; if ( s >= m ) break ; } cout << ans ; }

870A - Search for Pretty Integers

link 870A - Search for Pretty Integers #include < bits / stdc ++. h > using namespace std ; int main (){ int n , m ; cin >> n >> m ; int a [ n ], b [ m ]; for ( int i = 0 ; i < n ; i ++) cin >> a [ i ]; for ( int i = 0 ; i < m ; i ++) cin >> b [ i ]; int ans = 999999 ; for ( int i = 0 ; i < n ; i ++){ for ( int j = 0 ; j < m ; j ++){ if ( a [ i ]== b [ j ]){ ans = min ( ans , a [ i ] ); } else { ans = min ( ans , 10 * a [ i ]+ b [ j ]); ans = min ( ans , 10 * b [ j ]+ a [ i ]); }   }   } cout << ans ;   }

898A - Rounding

                                                                 898A - Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has a non-negative integer  n . He wants to round it to nearest integer, which ends up with  0 . If  n  already ends up with  0 , Vasya considers it already rounded. For example, if  n  = 4722  answer is  4720 . If  n  = 5  Vasya can round it to  0  or to  10 . Both ways are correct. For given  n  find out to which integer will Vasya round it. Input The first line contains single integer  n  ( 0 ≤  n  ≤ 10 9 ) — number that Vasya has. Output Print result of rounding  n . Pay attention that in some cases answer isn't unique. In that case pr...

805A - Fake NP

805A - Fake NP time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of  longest-path . You are given  l  and  r . For all integers from  l  to  r , inclusive, we wrote down all of their integer divisors except  1 . Find the integer that we wrote down the maximum number of times. Solve the problem to show that it's not a  NP  problem. Input The first line contains two integers  l  and  r  ( 2 ≤  l  ≤  r  ≤ 10 9 ). Output Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them. Examples input Copy 19 29 output Copy 2 input Copy 3 6 output Copy 3 Note Definition of a divisor:  https://ww...
                                                             798A  -   . Mike and palindrome              memory limit per test 256 megabytes input standard input output standard output Mike has a string  s  consisting of only lowercase English letters. He wants to  change exactly one  character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings " z ", " aaa ", " aba ", " abccba " are palindromes, but strings " codeforces ", " reality ", " ab " are not. Input The first and single line contains string  s  ( 1 ≤ | s | ≤ 15 ). Output Print " YES " (without quotes) if Mike can change  exactly  one character so that the resulti...

798A - Mike and palindrome

                                                             798A  -   . Mike and palindrome              memory limit per test 256 megabytes input standard input output standard output Mike has a string  s  consisting of only lowercase English letters. He wants to  change exactly one  character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings " z ", " aaa ", " aba ", " abccba " are palindromes, but strings " codeforces ", " reality ", " ab " are not. Input The first and single line contains string  s  ( 1 ≤ | s | ≤ 15 ). Output Print " YES " (without quotes) if Mike can change  exactly  one character so that the resulting string is palindrome or " NO " (wi...