欧拉题4
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.
三位数积产生的最大回文数
//三位数乘积的最大的回文数
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <vector>
using namespace std;
int IsPalin(char * c, int len)//是否是回文,一开始的字符数组的
{
char * c_turn = new char[len+1];
int i;
for(i=0;i<len;i++)
{
c_turn[i] = c[len-1-i];
}
//c_turn[len] = "\0";
for(i=0;i<len;i++)
{
if(c_turn[i]!=c[i])
{
delete(c_turn);
return 0;
}
}
delete [] c_turn;
return 1;
}
int IsPalinStr(string & str)//是否是回文,后来的string的
{
string str_turn = str;
string::iterator it,jt;
for(it=str.end()-1,jt=str_turn.begin();jt!=str_turn.end();it--,jt++)
{
*jt = *it;
}
cout<<"str_turn="<<str_turn<<endl;
if(str_turn == str)
return 1;
else
return 0;
}
int IsPalinStrOne(string & str)//不用另外一个string的版本
{
string::iterator it,jt;
for(it=str.end()-1,jt=str.begin();it>=jt;it--,jt++)
{
// cout<<"i="<<*it<<endl;
// cout<<"j="<<*jt<<endl;
if(*jt != *it)
return 0;
}
return 1;
}
int FindMaxVector(vector<int> &sum)//辅助的函数,把是回文的全push进vector,再调用找最大的
{
vector<int>::iterator it = sum.begin();
int max = *it;
for(it = sum.begin();it != sum.end();it++)
{
if(*it>max) max=*it;
}
return max;
}
int IsPalinInt(int arg)//后来用的用数值来判断是否回文
{
int reverse=0,tmp = arg;
while(tmp!=0)
{
reverse = reverse*10+tmp%10;
tmp = tmp/10;
}
if(reverse==arg)
return 1;
else
return 0;
}
int main()
{
int flag,i,j,tmp;
/* char *c = new char[1024];
cin>>c;
flag = IsPalin(c,strlen(c));
cout<<flag;
delete(c);*/
string str;
// cin>>str;
// flag = IsPalinStrOne(str);
// cout<<flag<<endl;
char c[10];
vector<int> sum;
int max=0;
for(i=100;i<=999;i++)
{
for(j=100;j<=999;j++)
{
tmp = j*i;
/*sprintf(c,"%d",tmp);
str = string(c);
if(IsPalinStrOne(str))
{
cout<<"i,j "<<i<<" "<<j<<endl;
cout<<"max="<<tmp<<endl;
return 1;
//sum.push_back(tmp);
}*/
if(IsPalinInt(tmp)&&max<=tmp)//几个版本都编了一下,这个是最后一次编的
{
cout<<"i,j "<<i<<" "<<j<<endl;
max = tmp;
}
}
}
cout<<"max="<<max<<endl;
//cout<<"max_end="<<FindMaxVector(sum)<<endl;
//cout<<"test="<<IsPalinInt(9919)<<endl;
cout<<"end"<<endl;
}
答案是906609
欧拉题5
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
程序找不到了,只有答案232792560
欧拉题6
The sum of the squares of the first ten natural numbers is,
The square of the sum of the first ten natural numbers is,
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
一个纯粹数学题,前100个自然数的平方和与和平方的差
//前100个自然数的平方和与和平方的差
#include <iostream>
using namespace std;
int Diff(int n)
{
int sum_squar=0,squar_sum=0;
for(int i=0;i<n;i++)
{
sum_squar += (i+1)*(i+1);
squar_sum += (i+1);
}
squar_sum *=squar_sum;
return squar_sum-sum_squar;
}
int main()
{
int n;
cin>>n;
cout<<Diff(n);
}