Luogu P1876开灯[数论]

先给出一个结论:
对于每个输出的答案,都是完全平方数。
证明:
除了平方数,其它每个数的任意因子都有另一因子与之对应。
So,

/*
ID:hh826532
PROB:
LANG:C++
*/
#define _FILE_ ""
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define fr(i,a,b) for(int i=a,_end_=b;i<=_end_;i++)
#define fd(i,a,b) for(int i=a,_end_=b;i>=_end_;i--)
#define frei(s) freopen(s,"r",stdin)
#define freo(s) freopen(s,"w",stdout)
#define ll long long
#define uns unsigned
using namespace std;
#define rt return
#define inf 0x3f3f3f3f
#define infll 4557430888798830399ll
#define pc(x) putchar(x)
#define spc putchar(' ')
#define mem(x,y) memset(x,y,sizeof(x))
#define memm(x,y,z) memset(x,y,sizeof(x[0])*z)
#define gc getchar()
#define ln pc('\n')
#define writeint(x) printf("%d",x)
ll lowbit(ll x)
{
    rt x&(-x);
}
int readuint(){
    int s=0;
    char c=getchar();
    while(c<'0'||c>'9')c=gc;
    while(c>=48&&c<='9'){
        s=s*10+c-48;
        c=gc;
    }
    rt s;
}
int readint(){
    int s=0,k=1;
    char c=getchar();
    while((c<'0'||c>'9')&&c!='-')c=gc;
    if(c=='-'){
        k=-1;
        c=gc;
    }
    while(c>=48&&c<='9'){
        s=s*10+c-48;
        c=gc;
    }
    rt s*k;
}
void OPENFILE(){
    char FILENAME[50];
    if(strlen(_FILE_)==0)rt;
    sprintf(FILENAME,"%s.in",_FILE_);
    frei(FILENAME);
    sprintf(FILENAME,"%s.out",_FILE_);
    freo(FILENAME);
}
int exgcd(int a,int b,int &x,int &y)  
{  
    if(b==0)  
    {  
        x=1;
        y=0;  
        return a;  
    }  
    int d=exgcd(b,a%b,x,y);  
    int temp=x;  
    x=y;  
    y=temp-a/b*y;  
    return d;  
}  
double log(double x,double y)
{
    rt log10(x)/log10(y);
}
ll gcd(ll x,ll y)
{
    rt y?gcd(y,x%y):x;
}
ll P(ll x,ll y)//x>=y
{
    ll r=1;
    fr(i,1,y)
        r*=(x-i+1);
    rt r;
}
ll P(ll x,ll y,ll modnum)//x>=y
{
    ll r=1;
    fr(i,1,y)
        r=r*(x-i+1)%modnum;
    rt r;
}
ll n;
int main(){
    OPENFILE();
    scanf("%lld",&n);
    int k=sqrt(n);
    fr(i,1,k)
        printf("%lld%c",i*i,i==k?'\n':' ');
    rt 0;
}
#1
AC
2ms/1359kB

#2
AC
5ms/1355kB

#3
AC
2ms/1355kB

#4
AC
1ms/1355kB

#5
AC
5ms/1359kB

你可能感兴趣的:(数论)