User:ProjectEuler
外观
ProBlem14
[编辑]#include <iostream>
using namespace std;
int main()
{
int i, j, maxl = 0, res;
for( i = 1000000; i >= 1; i --)
{
int c = 0;
__int64 j = i;
if(i % 10000 == 0)
cout<<i<<endl;
while(j != 1)
{
if(j % 2 == 0)
j/=2;
else j = j * 3 + 1;
c ++;
}
if(c > maxl)
{
maxl = c;
res = i;
}
}
cout<<res<<endl;
}
answer 837799
Problem15
[编辑]#include <iostream>
using namespace std;
#define MAX 21
__int64 dp[MAX][MAX];
int main()
{
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for(int i = 0; i <= 20; i ++)
{
for(int j = 0; j <= 20; j ++)
{
if(i-1 >= 0)
dp[i][j] += dp[i-1][j];
if(j-1 >= 0)
dp[i][j] += dp[i][j-1];
}
}
printf("%I64d\n", dp[20][20]);
}
answer 137846528820
Problem16
[编辑]#include <iostream>
using namespace std;
char str[1000];
char tmp[1000];
int main()
{
for(int i = 0; i < 999; i ++)
str[i] = '0';
str[i] = '1';
str[i+1]= '\0';
for( i = 1; i <= 1000; i ++)
{
int jw = 0, a;
for(int j = 999; j >= 0 ; j --)
{
a = (str[j] - '0') * 2;
tmp[j] = (a + jw ) % 10 + '0';
jw = (a + jw)/10;
}
tmp[1000] = '\0';
for(j = 0; j < 1000; j ++)
str[j] = tmp[j];
}
cout<<str<<endl;
int sum = 0;
for(i = 0; i < 1000; i ++)
sum += str[i] - '0';
cout<<sum<<endl;
}
answer 1366