151C - Win or Freeze - CodeForces Solution


games greedy math number theory *1400

Please click on ads to support us..

Python Code:

import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os
 
def value(): return tuple(map(int, input().split()))
def values(): return tuple(map(int, sys.stdin.readline().split()))
def inlst(): return [int(i) for i in input().split()]
def inlsts(): return [int(i) for i in  sys.stdin.readline().split()]
def inp(): return int(input())
def inps(): return int(sys.stdin.readline())
def instr(): return input()
def stlst(): return [i for i in input().split()]
    
 
  
def solve():
    nn=inp()
    n=nn
    if n<=2:
       m=int(math.sqrt(n))+1
    ind =2
    l=[]
    while ind <= math.sqrt(n):
        while n%ind == 0:
            n=n//ind
            l.append(ind)

        ind+=1
        if len(l) ==2 and l[0]*l[1]!=nn:
            print(1)
            print((l[0]*l[1]))
            return 
        if len(l) >2 :
            print(1)
            print((l[0]*l[1]))
            return 
        
    if len(set(l))==1:
      print(2)
    else:
        print(1)
        print(0)
        

 

solve()

C++ Code:

#include <bits/stdc++.h>

using namespace std;
#define ll long long int

int main()
{
  ll q;
  cin >> q;

  ll temp = q;
  vector<ll> v;

  for (ll i = 2; i * i <= q; i++)
  {
    if (temp % i == 0)
    {
      while (temp % i == 0)
      {
        v.push_back(i);
        temp /= i;
      }
    }
  }

  if (temp != 1)
  {
    v.push_back(temp);
  }

  ll n = v.size();

  if (n <= 1)
  {
    cout << "1\n0";
  }
  else if (n > 2)
  {
    cout << 1 << endl;
    cout << v[0] * v[1];
  }
  else
  {
    cout << 2 << endl;
  }


  return 0;
}


Comments

Submit
0 Comments
More Questions

1324B - Yet Another Palindrome Problem
525A - Vitaliy and Pie
879A - Borya's Diagnosis
1672B - I love AAAB
1673A - Subtle Substring Subtraction
1345A - Puzzle Pieces
711A - Bus to Udayland
779B - Weird Rounding
1703D - Double Strings
1704C - Virus
63A - Sinking Ship
1704B - Luke is a Foodie
298B - Sail
239A - Two Bags of Potatoes
1704E - Count Seconds
682A - Alyona and Numbers
44A - Indian Summer
1133C - Balanced Team
1704A - Two 0-1 Sequences
1467A - Wizard of Orz
1714E - Add Modulo 10
1714A - Everyone Loves to Sleep
764A - Taymyr is calling you
1714B - Remove Prefix
1264F - Beautiful Fibonacci Problem
52A - 123-sequence
1543A - Exciting Bets
1714D - Color with Occurrences
215B - Olympic Medal
1445A - Array Rearrangment