这道题是基本的输出格式问题,还是那句话细节决定成败。
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
#include
<
stdio.h
>
2 #include < math.h >
3
4 int main()
5 {
6 __int64 s,t;
7 double p,q;
8 while (scanf( " %I64d " , & s) != EOF && s)
9 {
10
11 p = log10(( 1.0 * s) / 6 ) + log10( 1.0 * (s + 1 )) + log10( 1.0 * (s + 2 ));
12 t = ( int )p;
13 p = p - ( int )p;
14 q = pow( 10.0 ,p);
15 printf( " %.2lfE%d\n " ,q,t); // 注意数据类型的匹配
16 /* s*(s+1)(s+2)/6=q*10^n
17 因为:位权是10的共有t=(int)p个(取对数得到,和求整数的位数类似),
18 两边同时取对数,经移项可得q */
19 } return 0 ;
20 }
21 /* 科学计数法的表示挺多的:
22 c++的函数:
23 cout<<setiosflags(ios::fixed)<<setprecision(2)<<pow(10,a)<<'E'<<int(b)<<endl;
24 也可以对求和结果sum,处理
25 c=0;
26 while (sum>=10)
27 {
28 c++;
29 sum/=10;
30 }
31 printf ("%.2lfE%d\n",sum,c);
32
33 */
2 #include < math.h >
3
4 int main()
5 {
6 __int64 s,t;
7 double p,q;
8 while (scanf( " %I64d " , & s) != EOF && s)
9 {
10
11 p = log10(( 1.0 * s) / 6 ) + log10( 1.0 * (s + 1 )) + log10( 1.0 * (s + 2 ));
12 t = ( int )p;
13 p = p - ( int )p;
14 q = pow( 10.0 ,p);
15 printf( " %.2lfE%d\n " ,q,t); // 注意数据类型的匹配
16 /* s*(s+1)(s+2)/6=q*10^n
17 因为:位权是10的共有t=(int)p个(取对数得到,和求整数的位数类似),
18 两边同时取对数,经移项可得q */
19 } return 0 ;
20 }
21 /* 科学计数法的表示挺多的:
22 c++的函数:
23 cout<<setiosflags(ios::fixed)<<setprecision(2)<<pow(10,a)<<'E'<<int(b)<<endl;
24 也可以对求和结果sum,处理
25 c=0;
26 while (sum>=10)
27 {
28 c++;
29 sum/=10;
30 }
31 printf ("%.2lfE%d\n",sum,c);
32
33 */