Niu off the second game

Contest link

Question D:
Small thinking and regularity.
First, we find that 25/5 is exactly divisible.
This is used as a breakthrough point. Then for all numbers smaller than 5, the number 25 / i will not be repeated, and the i-th number is also the number in the set. i (from large to small); when it is greater than 5, there will be duplication, that is, the value of 25 / i will become dense, we can find that these values ​​are continuous until it is 1.

#include <bits/stdc++.h>

using namespace std;

int n,x;
int t;
int main()
{
    
    
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> t;
    while(t--)
	{
    
    
        cin >> n >> x;
        
        if(x <= int(sqrt(n)))
		{
    
    
            cout << x << '\n';
        }
		else
		{
    
    
            int cnt = int(sqrt(n));
            
            cnt += (n / (cnt + 1) - n / x) + 1;
            //这一步不能写成  cnt += (cnt - n / x);
            //  n=24 k=5
            cout << cnt << '\n';
        }
    }
    return 0;
}

Question F
Double-ended queue will not solve the problem for the time being

Question I
When the prime number is not a prime number such as 2, 3, 5, and 7, you need to know how many digits it is

#include <bits/stdc++.h>
#define maxn 4000086

using namespace std;

const int p = 1e9 + 7;

int n;
int prm[maxn], cnt;
bool tag[maxn];
int f[maxn], g[maxn];
//  f[i] 存的是 i 最小的质因子 
int main(){
    
    
	scanf("%d", &n);
	for(int i = 2;i <= n;i++)
	{
    
    
		if(!tag[i]) prm[++cnt] = i, f[i] = i;
		
		for(int j = 1;j <= cnt && prm[j] * i <= n;j++)
		{
    
    
			tag[prm[j] * i] = true, f[prm[j] * i] = prm[j];
			if(i % prm[j] == 0) break;
		}
	}
	for(int i = 2;i <= n;i++){
    
    //   用g[i]表示i是几位数
		int x = i;
		g[i] = 1;
		while(x){
    
    
			x /= 10;
			g[i] *= 10;
		}
	}
	int ans = 0;
	for(int i = 2;i <= n;i++)
	{
    
    
		int sum = 0, x = i;
		while(x ^ 1)
		{
    
    	// f[i] 始终为最小质因数  模拟一下就能懂这个过程 
			sum = (1ll * sum * g[f[x]] + f[x]) % p; 
			x /= f[x];
		}
		ans = (ans + sum) % p;
	}
	printf("%d", ans);
}

J question
thinking question

#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
    
    
    cin >> n;
    int a[50];
    a[0]= 1;
    a[1]= 2;
    //  小于40 就用斐波那契数列
    for (int i = 1; i <= min(40, n); i++)
    {
    
    
        cout << a[i] <<' ';
        a[i+1] = a[i]+a[i-1];
    }
    //  大于40就用斐波那契数列 + 一堆1往后托
    for (int i = 41; i <= n; i++)
        cout << 1  <<' ';
    return 0;
}

Guess you like

Origin blog.csdn.net/cosx_/article/details/113625031