CodeForces 233B. Non-square Equation【狀壓】
#include<cstdio>
#include<cmath>
typedef __int64 LL;
bool Judge(LL x,LL s) {
LL sum=0;
while(x) {
sum=sum+x%10; x/=10;
}
return sum==s;
}
int main()
{
LL N;
while(~scanf("%I64d",&N)) {
LL n=17*9,ans=-1;
for(int i=1;i<=n;++i) {
LL t=i*i+4*N;
LL tem=sqrt(t);
if(tem*tem==t) if( (tem-i)%2==0) {
LL x=(tem-i)>>1;
if(Judge(x,i)) {
ans=x; break;
}
}
}
printf("%I64d\n",ans);
}
return 0;
}
相關文章
- Codeforces 11D A Simple Task 題解 [ 藍 ] [ 狀壓 dp ]
- Diophantine equation
- 狀壓 dp
- 狀壓DP
- [狀壓dp] 最短Hamilton路徑(模板題+狀壓dp)
- 狀態壓縮
- 互不侵犯 (狀壓)
- [題解]CF1775E The Human Equation
- ME5701 Linear stability analysis of Mathieu equation
- HDU 1074 Doing Homework(狀壓DP)
- 簡易狀態壓縮DP
- 狀壓DP基礎入門
- HDU 3006 The Number of set (狀態壓縮)
- 狀壓 + 網路流 -- Escape HDU - 3605
- 論文閱讀 狀態壓縮
- 合理安排(狀壓dp,包括技巧)
- POJ3279 Fliptile【狀態壓縮+DFS】
- NOI2001 炮兵陣地(狀壓dp)
- E - Remove Pairs(狀壓dp+博弈論)REMAI
- BZOJ5068: 友好的生物(狀壓 貪心)
- HDU 5816 Hearthstone(狀態壓縮DP+概率)
- POJ 2777 Count Color (線段樹+狀態壓縮)
- hdu--5418Victor and World+狀態壓縮DP
- 分組(狀壓dp+技巧:快速列舉子集)
- Codeforces
- bzoj4145: [AMPPZ2014]The Prices(狀態壓縮+Dp)
- 百練4124:海賊王之偉大航路(狀壓DP)
- 動態規劃中初識狀態壓縮(入門)動態規劃
- CodeForces 1307
- 9.11 codeforces
- 【CodeForces訓練記錄】Codeforces Global Round 27
- 一類哈密頓路徑/迴路為背景的狀壓dp
- CF79D Password (差分+狀壓 dp+最短路/bfs)
- codeforces Photo of The Sky
- Codeforces 專區
- codeforces 11/10
- CodeForces 1935A
- Codeforces Round 955
- Codeforces - Jzzhu and Numbers