CSES - Datatähti 2023 alku - Results
Submission details
Task:Kertoma
Sender:Ihminen
Submission time:2022-11-03 18:51:20 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int findDigits(int)':
input/code.cpp:42:19: error: 'log10' was not declared in this scope
   42 |         digits += log10(i);
      |                   ^~~~~
input/code.cpp:44:12: error: 'floor' was not declared in this scope
   44 |     return floor(digits) + 1;
      |            ^~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:108:17: warning: unused variable 'num' [-Wunused-variable]
  108 |             int num = x;
      |                 ^~~
input/code.cpp:113:17: warning: unused variable 'carry' [-Wunused-variable]
  113 |             int carry=0;
      |                 ^~~~~

Code

#include <iostream>
#include <vector>
#include <sstream>
#include <list>
#include <algorithm>
typedef long long ll;
 
#define M 1000000007
#define N (1 << 18)
 
using namespace std;
 
int suurinNumero = 0;
int vastaus = 0;
int lukuMäärä = 0;
 
vector<int> split(const string & str, char delimiter) {     
    vector<int> tokens;     
    string token;     
    istringstream tokenStream(str);     
    while (getline(tokenStream, token, delimiter)) {      
        tokens.push_back(stoi(token));     
    }     
    return tokens;  
}
 

int findDigits(int n)
{
    // factorial exists only for n>=0
    if (n < 0)
        return 0;
 
    // base case
    if (n <= 1)
        return 1;
 
    // else iterate through n and calculate the
    // value
    double digits = 0;
    for (int i = 2; i <= n; i++)
        digits += log10(i);
 
    return floor(digits) + 1;
}
 
int main() {
    
    string inputString;
    vector<int> tNumerot = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    vector<int> Numerot = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    getline(cin, inputString);
    vector<int> iNumerot = split(inputString, ' ');
    int loopinAlku = 0;
    int laskettuNumeroMäärä = 0;
 
    for (int i: iNumerot) {
        lukuMäärä += i;
        if (i > suurinNumero) {
            suurinNumero = i;
        }
    }
 
    if (suurinNumero <= 100) {
        loopinAlku = 2;
        for (int x = loopinAlku; x < 12000; x++)
        {
            /*ll väli = factorial(x);
            stringstream ss;
            ss << väli;
            string väliString = ss.str();
            cout << väliString << "\n";*/
            int num = x;
            vector<int> res;
            res.push_back(1);
            int carry = 0;
            tNumerot = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
            for (long i = 2; i <= num; i++)
            {
                for (unsigned long int j = 0; j < res.size(); j++)
                {
                    int tmp = res[j] * i;
                    res[j] = (tmp + carry) % 10;
                    carry = (tmp + carry) / 10;
                }
                while (carry != 0)
                {
                    res.push_back(carry % 10);
                    carry = carry / 10;
                }
            }
            for (int i = res.size() - 1; i >= 0; i--)
            {
                tNumerot[res[i]] += 1;
            }

            if (tNumerot == iNumerot)
            {
                vastaus = x;
                break;
            }
        }
    }
    else
    {
        loopinAlku = 11990;
        for (int x = loopinAlku; x < 12000; x++) {
            int num = x;
            int luvut = 0;
            laskettuNumeroMäärä = 0;
            vector<int> res;
            res.push_back(1);
            int carry=0;
            luvut = findDigits(x);
 
            if (luvut == lukuMäärä) {
                vastaus = x;
                break;
            }
        }
       
    }
    
    
 
    
 
    
    cout << vastaus << "\n";
 
}