恶心的输出......
AC代码如下:
#include <iostream>
#include <cstdio>
using namespace std;
__int64 gcd( __int64 a, __int64 b ){
__int64 temp;
if( a < b ){
temp = a;
a = b;
b = temp;
}
while( b != 0 ){
temp = a % b;
a = b;
b = temp;
}
return a;
}
__int64 lcm( __int64 a, __int64 b ){
__int64 temp = gcd( a, b );
return a / temp * b;
}
int getlength( __int64 n ){
int cnt = 0;
while( n ){
cnt++;
n /= 10;
}
return cnt;
}
int main(){
int N;
double ans;
__int64 a, b, result;
while( scanf( "%d", &N ) != EOF ){
ans = 0;
for( int i = 1; i <= N; i++ ){
ans += N / ( i * 1.0 );
}
result = (__int64)ans;
b = 1;
for( __int64 i = 1; i <= N; i++ ){
b = lcm( b, i );
}
a = 0;
for( __int64 i = 1; i <= N; i++ ){
a += ( N * b / i ) % b;
a %= b;
}
//约分
__int64 temp;
temp = gcd( a, b );
a = a / temp;
b = b /temp;
int number1, number2;
number1 = getlength( result );
number2 = getlength( b );
if( a == 0 ){
cout << result << endl;
continue;
}
//第一行
for( int i = 0; i < number1; i++ ){
cout << " ";
}
printf( " %I64d\n", a );
//第二行
printf( "%I64d ", result );
for( int i = 0; i < number2; i++ ){
cout << "-";
}
cout << endl;
//第三行
for( int i = 0; i < number1; i++ ){
cout << " ";
}
printf( " %I64d\n", b );
}
return 0;
}