「CF471C」MUH and House of Cards
题解
i层高至少需要(3*i+1)*i/2;
显然n张card只需要枚举到根号n
如果n-(3*i+1)*i/2可以被三整除,ans++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> #include<set> #include<map> #define pa pair<int,int> #define inf 1000000000 #define ll long long using namespace std; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } ll n; int ans; int main() { n=read(); for(ll i=1;i<=sqrt(n);i++) { ll t=(3*i+1)*i/2; if(n<t)break; if((n-t)%3==0)ans++; } if(ans>0)printf("%d",ans); else puts("0"); return 0; } |
Subscribe