Search
 
SCRIPT & CODE EXAMPLE
 

CPP

cf 633b trivial problem explanation

#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std;

const int INF=0x3f3f3f3f;
const int maxn=500100;

int m,cnt;
int num[maxn],a[maxn];
int fun(int n)
{
    int ans=0;
    while(n)
    {
        n/=5;
        ans+=n;
    }
    return ans;
}

int main()
{
    for(int i=0; i<maxn; i++)
        a[i]=fun(i);
    while(~scanf("%d",&m))
    {
        cnt=0;
        int i;
        for(i=0; i<maxn; i++)
        {
            if(a[i]==m)
            {
                num[cnt++]=i;
            }
        }
        printf("%d
",cnt);
        if(cnt)
        {
            for(i=0; i<cnt; i++)
            {
                if(i) printf(" ");
                printf("%d",num[i]);
            }
            printf("
");
        }
    }
    return 0;
}

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int MAXN = 1e9;

int fun(int n)
{
    int cnt = 0;
    while(n)
    {
        n/=5;
        cnt+=n;
    }
    return cnt;
}
int Two(int l, int r, int m)
{
    int ans = 0;
    while(r >= l)
    {
        int mid = (l + r) >> 1;
        int res = fun(mid);
        if(res < m)
            l = mid + 1;
        else if(res >= m)
        {
            r = mid - 1;
            ans = mid;
        }
    }
    return ans;
}
int main()
{
    int m;
    while(cin >> m)
    {
        int l = 1, r = MAXN;
        int L = Two(l, r, m), R = Two(l, r, m+1);
        if(L == 0 || fun(R-1) != m) cout << 0 << endl;
        else
        {
            cout << R - L << endl;
            for(int i = L; i <= R-1; i++)
            {
                if(i > L) cout << " ";
                cout << i;
            }
            cout << endl;
        }
    }
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: MPI_Sendrecv 
Cpp :: python Difference Array | Range update query in O(1) 
Cpp :: stack in c++ data structure 
Cpp :: how to delete repeated element in stack c++ 
Cpp :: How to write string in lpcstr in c++ 
Cpp :: convert "c++ to c" code online 
Cpp :: 7 9 C:UsersAliyahDocumentsshut up.cpp [Error] expected unqualified-id before string constant 
Cpp :: auto keyword 
Cpp :: https://www.geeksforgeeks.org/a-program-to-check-if-strings-are-rotations-of-each-other/ 
Cpp :: clang does not recognize std::cout 
Cpp :: cpp full form 
Cpp :: 2d vector size c++ 
Cpp :: npm wasm 
Cpp :: calculate number of edges of graph in data structure c++ 
Cpp :: android call custom managed method from native code 
Cpp :: c++ string not printing 
Cpp :: typeid to string c++ 
Cpp :: delete node in a linked list leetcode 
Cpp :: executing linux scripts 
Cpp :: how to run a cpp file in visual studio 
Cpp :: c++ sudoku solver 
Cpp :: palindrome string 
Cpp :: how to replace an element in array in c++ 
Cpp :: program to check smallest num in three numbers in c++ 
Cpp :: c++ how to skip the last element of vector 
C :: What are the 3 basic types of Plate Boundaries? Explain their differences (how they act). 
C :: arduino serial read write structure 
C :: string to int c 
C :: see if two strings are equal in C 
C :: best sites for loop practice c 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =