History repeat itself 统计非平方数
2012-08-07 18:10
141 查看
题意:
从1到。。。INF,统计第N个不能开平方数,并求其和。。
算法:
技巧题:
View Code
从1到。。。INF,统计第N个不能开平方数,并求其和。。
算法:
技巧题:
View Code
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<iostream> #include<vector> #include<string> #include<math.h> #include<map> #include<set> #include<algorithm> using namespace std; int T; long long N; int main( ) { scanf("%d",&T); while( T-- ) { scanf("%I64d",&N); unsigned long long temp=0, ans = 0, tp; unsigned long long sb = 0; for( long long i = 2; i <= N; i++) { temp += i * i - (i-1)*(i-1) - 1 ; sb += (i * i - (i-1)*(i-1)) * (i - 1); if( temp>=N ) { tp = temp - N; ans = i * i - tp - 1; sb = sb - tp * (i - 1); break; } } if( N == 1 ) { ans = 2; sb = 2; } printf("%I64u %I64u\n",ans,sb); } }
相关文章推荐
- 【HDU - 4342】History repeat itself(数学)
- 二分查找+数学 HDOJ 4342 History repeat itself
- hdu 4342 History repeat itself
- History repeat itself 解题
- HDOJ 4342 History repeat itself
- HDU 4342 - History repeat itself
- HDU 4342——History repeat itself——————【数学规律】
- hdu 4342 History repeat itself(思维)
- hdu - 4342 - History repeat itself - 纯数学水题
- HDU 4342 History repeat itself
- HDU 4342 History repeat itself 2012 Multi-University Training Contest 5
- HDU 4342 History repeat itself(数学规律)
- HDU 4342 ——History repeat itself
- hdu 4342 History repeat itself(数学题)
- HDU 4342 History repeat itself 简单公式
- 2012 Multi-University Training Contest 5:History repeat itself
- HDU4342 History repeat itself
- hdu4342 History repeat itself-------多校联合五
- HDU4342 History repeat itself数学规律题
- 【杂题】 HDOJ 4342 History repeat itself