标签:hdu
2 10 19
Case #1: 0 Case #2: 1对于一位的状况,3,4,5,6明显是-1对于二位,解方程a*x+b=n对于三位,接长城a*x^2+b*x+c=n其他的从4进制开始枚举即可#include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; #define up(i,x,y) for(i=x;i<=y;i++) #define down(i,x,y) for(i=x;i>=y;i--) #define mem(a,b) memset(a,b,sizeof(a)) #define w(x) while(x) #define ll __int64 int main() { int t,cas=1; ll n,tem,r,i,j,k,a,b,c,ans; scanf("%d",&t); w(t--) { ans=0; scanf("%I64d",&n); printf("Case #%d: ",cas++); if(n>2&&n<7) { printf("-1\n"); continue; } up(i,3,6) up(j,3,6) if((n-i)%j==0 && (n-i)/j>max(i,j)) ans++; up(i,3,6) up(j,3,6) up(k,3,6) { a=i,b=j,c=k-n; tem=(ll)sqrt(b*b-4*a*c+0.5); if(tem*tem!=b*b-4*a*c) continue; if((tem-b)%(2*a)) continue; tem=(tem-b)/(2*a); if(tem>max(i,max(j,k))) ans++; } for(i=4;i*i*i<=n;i++) { tem=n; w(tem) { r=tem%i; if(r<3||r>6) break; tem/=i; } if(!tem) ans++; } printf("%I64d\n",ans); } return 0; }
HDU4937:Lucky Number,布布扣,bubuko.com
标签:hdu
原文地址:http://blog.csdn.net/libin56842/article/details/38583747