hdu 4342 数学规律
2012-08-09 11:25
351 查看
/* 首先先根据n求k,k是满足不等式 k*k-k<n的最大正整数。 不等式的解是: (1+sqrt(1+4*n))/2;必需对这个数上取整,然后减一就是k了。 那么 idx=n+k; 然后再根据 idx和k 求 ans; LL sum=k*idx; LL tmp=(1+k)*k*(2*k+1)/6-k; ans=sum-tmp; idx 和 ans 即为要求结果!! */ #include<iostream> #include<algorithm> #include<cmath> #include<cstdio> using namespace std; #define LL long long int t; LL n,idx,ans; int main() { scanf("%d",&t); while(t--) { scanf("%lld",&n); idx=(LL)ceil((1+sqrt(1+4.0*n))/2)-1+n; LL k=idx-n; LL sum=k*idx; LL tmp=(1+k)*k*(2*k+1)/6-k; ans=sum-tmp; cout<<idx<<" "<<ans<<endl; } return 0; }
相关文章推荐
- HDU 4342——History repeat itself——————【数学规律】
- HDU 4342 History repeat itself(数学规律)
- HDU 3573 Buy Sticks(数学规律)
- HDU 1722 Cake【规律+数学】
- hdu 2114 找规律的数学题目
- 【HDU】-1005-Number Sequence(数学,规律)
- HDU 5914 Triangle 数学找规律
- bfs+队列 数学规律 HDU Problem Q
- HDU-5810-Balls and Boxes-数学推导(找规律)
- hdu 1030 Delta-wave(数学题+找规律)
- HDU 4279 Number(数学题,找规律)
- hdu 5389 Zero Escape DP+数学规律 给出证明 2015 Multi-University Training Contest 8
- HDU 1046 数学规律题
- 【规律】【贪心】【数学】HDU 5573 Binary Tree
- hdu 5505 GT and numbers(数学规律)
- hdu 2086 数学规律
- hdu 4091 Zombie’s Treasure Chest(数学规律+枚举)
- HDU:2050 折线分割平面(规律,数学,推导)
- HDU 5650 so easy(数学找规律)
- 数学题(找规律)-hdu-4371-Minimum palindrome