SPOJ Problem:Beehive Numbers

阅读题。。加上等差数列判断。。

#include<cstdio>
#include<cmath>
int n,s;
int main(){
    while(scanf("%d",&n)&&n!=-1){
        n--;
        if (n%6){printf("N\n");continue;}
        n/=3;
        s=int (sqrt(double(n)));
        if (s*(s+1)==n)printf("Y\n");
        else printf("N\n");
    }
}
时间: 2024-10-16 17:26:47

SPOJ Problem:Beehive Numbers的相关文章

素数筛法--SPOJ Problem 2 Prime Generator

质数(prime number)又称素数,除了1和它本身外,不能整除以其他自然数,换句话说就是该数除了1和它本身以外不再有其他的因数:否则称为合数.最小的质数是2. 要判断一个整数N是不是质数很简单,看它是否能被2到sqrt(N)之间的整数整除即可. def isPrime(n): if n%2==0: return False for i in xrange(3,int(math.sqrt(n)+1),2): if n%i==0: return False return True 不过要找出1

SPOJ Problem 7974:What&#39;s Next

求数列下一项,啥都不说了,贡献了N多WA... #include<cstdio> int main(){ int a,b,c; while(scanf("%d%d%d",&a,&b,&c)&&(a||b||c)){ if (b*2==c+a&&b!=a) printf("AP %d\n",2*c-b); else printf("GP %d\n",c*c/b); } return

SPOJ BALNUM Balanced Numbers 状压+数位DP

一开始想了一个用二进制状压的方法,发现空间需要的太大,光光memset都要超时 = = 其实不用每次都memset 也可以用三进制,一开始直接打表出所有的状态转移就好 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostream&g

SPOJ Problem:A Game with Numbers

突然就看到SPOJ升级了,让我好不适应.. 这一一道博弈论的题目,可以先前面暴力一下,易得小于十的为必胜态,十的时候必败,然后11到19又必胜,而且发现只要各位为零且这个数不为零就必败. 再依次验证上百,上千的数.. #include<cstdio> #include<cstring> int n; int main(){ scanf("%d",&n); if (n%10==0&&n!=0)printf("2\n");

SPOJ problem 42: Adding Reversed Numbers

这是一道水题,就是让你把给出的两个数倒置后相加再倒回来,模拟一下就行. #include<cstdio> int n,m,x,y,t; int main(){ for(scanf("%d",&t);t;t--){ scanf("%d%d",&n,&m); x=0;y=0; for (;n;n/=10)x=x*10+n%10; for (;m;m/=10)y=y*10+m%10; x+=y;y=0; for (;x;x/=10)y=

SPOJ Problem 7733:Happy Numbers I

找循环节..或者可以知道最后肯定会到1位数,可以手动求十以内的 #include<cstdio> #include<cstring> int n; int dt(int s,int t){ int r=s,p; if(s<10&&(s!=1&&s!=7))return -1; if (s==1)return t; p=0; while(r){ p+=(r%10)*(r%10); r/=10; } dt(p,t+1); } int main(){

SPOJ FANCY - FANCY NUMBERS

题目链接:http://www.spoj.com/problems/FANCY/ 题目大意:如果一串数字为555,那么我们可以将其写为(5,5,5) (5,55) (55,5) (555).现在给你一串数字,问它能有几种不同的写出方式. 解题思路:首先应该是无论有几个连续的都算作一种读出方式(题目上只举出了double和triple两种).那么对于一串连续相同的数字来说,不同读出方式相当于在这些数字之间插入空位将其隔开. 例如22222,插入零个空位C(4,0),一个空位C(4,1),两个C(4

SPOJ BALNUM Balanced Numbers(数位dp)

Balanced Numbers Time Limit:123MS     Memory Limit:1572864KB     64bit IO Format:%lld & %llu Submit Status Practice SPOJ BALNUM Description Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a balanced n

SPOJ - BALNUM - Balanced Numbers(数位DP)

链接: https://vjudge.net/problem/SPOJ-BALNUM 题意: Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a balanced number if: 1) Every even digit appears an odd number of times in its decimal representation 2)