1406: [AHOI2007]密码箱
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1629 Solved: 967
[ Submit][ Status][ Discuss]
Description
Input
Output
Sample Input
Sample Output
求出有多少个x满足
(x+1)(x-1)==kn
暴力枚举n的因子,设y|n
那么当(x+1)和(x-1)一个是y的倍数,一个是n/y的倍数,那么x就符合要求
#include<stdio.h>
#include<set>
using namespace std;
#define LL long long
set<LL> st;
int main(void)
{
LL n, i, a, b, j;
set<LL>::iterator it;
scanf("%lld", &n);
for(i=1;i*i<=n;i++)
{
if(n%i==0)
{
a = i, b = n/i;
for(j=0;j<=n;j+=b)
{
if(j-2>=0 && (j-2)%a==0)
st.insert(j-1);
if(j+2<n && (j+2)%a==0)
st.insert(j+1);
}
}
}
if(st.size()==0)
printf("None\n");
else
{
for(it=st.begin();it!=st.end();it++)
printf("%lld\n", *it);
}
return 0;
}
5800




被折叠的 条评论
为什么被折叠?



