Luogu P1876 Lighting Problem Solution

This problem is a math problem (also written below), so after careful study, it is found that after N rounds, only the lights of perfect square numbers less than N can be turned on. So it's easy to do next:

#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=sqrt(n);i++) printf("%d ",i*i);
    puts("");return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324978446&siteId=291194637