1104A - Splitting into digits - CodeForces Solution


constructive algorithms implementation math *800

Please click on ads to support us..

Python Code:

num = int(input())

maxDivisor = vezes = 0
lista = [1,2,3,4,5,6,7,8,9]

if num in lista:
    maxDivisor = num
else:
    for i in range(9,0,-1):
        if num % i == 0:
            maxDivisor = i
            break

vezes = int(num / maxDivisor)

print(vezes)

print(f"{maxDivisor} "*vezes)

C++ Code:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
void solve();

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("error.txt", "w", stderr);
  freopen("output.txt", "w", stdout);
#endif

  int t = 1;
  /*is Single Test case?*/ //cin >> t;
  while (t--)
  {
    solve();
    cout << endl;
  }

  // cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}

ll power(ll x, ll y)
{
  ll temp;
  if (y == 0)
    return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}

void SieveOfEratosthenes(int n)
{
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));

  for (int p = 2; p * p <= n; p++)
  {

    if (prime[p] == true)
    {

      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }

  // Print all prime numbers
  for (int p = 2; p <= n; p++)
    if (prime[p])
      cout << p << " ";
}

// bool isContains(queue<ll> q, ll x)
// {
//   while (!q.empty())
//   {
//     if (q.front() == x)
//       return true;
//     q.pop();
//   }
//   return false;
// }

// find ka code

// if (yo.find(s) !=string::npos){
//     cout<<"YES";
// }

// hashing ka code

// unordered_map<string, int>:: iterator p;
//   for (p = wordFreq.begin();
//        p != wordFreq.end(); p++)

bool isPalindrome(string S)
{
  // Stores the reverse of the
  // string S
  string P = S;

  // Reverse the string P
  reverse(P.begin(), P.end());

  // If S is equal to P
  if (S == P)
  {
    // Return "Yes"
    return true;
  }
  // Otherwise
  else
  {
    // return "No"
    return false;
  }
}
void solve()
{
  ll n;
  cin>>n;
  for(ll i=9;i>=1;i--){
    if(n%i==0){
      cout<<n/i<<endl;
      for(ll j=0;j<n/i;j++){
        cout<<i<<" ";
      }
      return;
    }
  }
   
}


Comments

Submit
0 Comments
More Questions

714B - Filya and Homework
31A - Worms Evolution
1691A - Beat The Odds
433B - Kuriyama Mirai's Stones
892A - Greed
32A - Reconnaissance
1236D - Alice and the Doll
1207B - Square Filling
1676D - X-Sum
1679A - AvtoBus
1549A - Gregor and Cryptography
918C - The Monster
4B - Before an Exam
545B - Equidistant String
1244C - The Football Season
1696B - NIT Destroys the Universe
1674A - Number Transformation
1244E - Minimizing Difference
1688A - Cirno's Perfect Bitmasks Classroom
219A - k-String
952A - Quirky Quantifiers
451B - Sort the Array
1505H - L BREAK into program
171E - MYSTERIOUS LANGUAGE
630D - Hexagons
1690D - Black and White Stripe
1688D - The Enchanted Forest
1674C - Infinite Replacement
712A - Memory and Crow
1676C - Most Similar Words