1.尼科彻斯定理
This program is to verify Theorem of Nicoqish.That is the cube of any integer can be represented as the sum of some continue odd numbers.For example, 8^3=512=57+59+61+63+65+67+69+71.
#include <iostream>
using namespace std;
int main()
{
int n,a,i;
while(1)
{
cout<<"Please input a integer to verify(0 to quit): ";
cin>>n;
if(n==0) __________; // (1)
// 输出等差数列,首项为a*a-a+1,公差为2,项数为n
a=n*n-n+1;
cout<<n<<"*"<<n<<"*"<<n<<"="<<n*n*n<<"="<<a;
for (i=1; __________;i++) // (2)
cout<<"+"<<__________; // (3)
cout<<endl;
}
return 0;
}
2.角谷猜想
This program is to verify Jiaogu Guess.That is given any natural number, if it is an even, divides 2, if it is an odd, multiple 3 and add 1, the result continues to be calculated analogously. After some times, the result is always 1.
#include <iostream>
using namespace std;
int main()
{
int n,a,i,cnt;
while(1)
{
cout<<"Please input a integer to verify(0 to quit): ";
cin>>n;
if(n==0) __________break; // (1)
cnt=0;
cout<<" ------ Results of verification: ------------ ";
do{
if(__________) // (2)
{
n=n*3+1;
cout<<"Step No."<<++cnt<<":"<<(n-1)/3<<"*3+1="<<n<<endl;
}
else
{
n/=2;
cout<<"Step No."<<++cnt<<":"<<2*n<<"/2="<<n<<endl;
}
} while(__________); // (3)
cout<<endl;
}
return 0;
}
3.四方定理
This program is to verify Theorem of Four Squares.That is all natural numbers can be represented as sum of no more than 4 squares of the numbers.e.g., 123=7*7+7*7+4*4+3*3.
#include <iostream>
using namespace std;
int main()
{
int i,j,k,l,number;
while(1)
{
cout<<"Please input a number to verify(0 to quit): ";
cin>>number;
if(number==0) __________; // (1)
cout<<" ------ Results of verification: ------------ ";
for(i=1;i<=number/2;i++)
for(j=0;j<=i;j++)
for(k=0;k<=j;k++)
for(l=0;l<=k;l++)
if(__________) // (2)
{
cout<<number<<"="<<i<<"*"<<i<<"+"<<j<<"*"<<j<<"+"<<k<<"*"<<k<<"+"<<l<<"*"<<l<<endl;
goto exit;
}
exit: cout<<" --------------------------------------------- ";
}
return 0;
}
4.亲密数
This is a program to find friendly numbers pair.Which means the sum of integer A's all factors (except A) equals to the sum of integer B's all factors (except B)< e.g. sum of integer 220's all factors are:1+2+4+5+10+11+20+22+44+55+110=284,and sum of integer 284's all factors are:1+2+4+71+142=220>
#include <iostream>
using namespace std;
int main()
{
int a,i,b,n,m;
cout<<"Please input the scale you want to find n: ";
cin>>n;
cout<<" There are following friendly--numbers pair smaller than "<<n<<endl;
for(a=1;a<n;a++)
{
for(__________;i<=a/2;i++) // (1)
if(!(a%i)) b+=i;
for(__________;i<=b/2;i++) // (2)
if(!(b%i)) m+=i;
if(__________&&a<b) // (3)
cout<<a<<".."<<b<<" ";
}
cout<<endl;
return 0;
}
5.自守数
This program will find the automorphic numbers.The defination of a automorphic number is: the mantissa of a natural number's square equals to itself. e.g., 5^2=25, 76^2=5776, 9376^2=87909376.
#include <iostream>
using namespace std;
int main()
{
int mul,number,k,kk;
for(number=0;number<10000;number++)
{
for(mul=number,k=1; __________;k*=10); // (1)
kk=k*10;
mul=number*number%kk;
if(__________) // (2)
cout<<number<<" ";
}
cout<<endl;
return 0;
}
6.特殊的四位数
This program will find the four figures which have the characteristic as follows: abcd=(ab+cd)^2. e.g., 3025=(30+25)*(30+25).
#include <iostream>
using namespace std;
int main() {
int n,a,b;
for(n=1000;n<10000;n++)
{
________________; // (1)
________________; // (2)
if((a+b)*(a+b)==n)
cout<<n<<" ";
}
cout<<endl;
return 0;
}
7.求方程cos(x)-x=0的根
This program is to find the real root of function cos(x)-x=0.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
float x0,x1=0.0;
while(1)
{
________________; // (1)
________________; // (2)
if(fabs(x0-x1)<1e-6)
break;
}
cout<<"The real root is "<<x1<<endl;
return 0;
}
8.特殊的3位数
This program is to find the Perfect Square Numbers. which have 3 digits, and 2 of them are the same. e.g.100, 121, 144, 225, 400, 441, 484, 676, 900.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int i,n,a,b,c;
for (i=10;i<=sqrt(1000);i++)
{
_______________; // (1)
a=n/100;
_______________; // (2)
c=n%10;
if (a==b || a==c || b==c)
cout<<n<<" ";
}
cout<<endl;
return 0;
}
9.三重回文数
This program is to find the Palindrome Numbers. whose square and cubic are also Palindrome Numbers.
#include <iostream>
using namespace std;
bool isPalindrome(int n)
{
int x,y=0;
x=n;
while (x!=0)
{
_______________; // (1)
_______________; // (2)
}
return y==n;
}
int main()
{
int m;
for(m=11;m<1000;m++)
{
if(isPalindrome(m) && isPalindrome(m*m) && isPalindrome(m*m*m))
{
cout<<m<<" "<<m*m<<" "<<m*m*m<<endl;
}
}
return 0;
}
10.SIX and NINE
This program is to find the numbers of SIX and NINE, which satisfy the formula SIX+SIX+SIX=NINE+NINE, where S,I,X,N,E stand for digits between 0 and 9.
#include <iostream>
using namespace std;
int main()
{
int i,x,a,b,c,d;
for(i=668;i<=999; _____________) // (1)
{
x=3*i/2;
a=i/10%10; b=x/100%10; c=x/1000; d=x%100/10;
if(____________________) // (2)
{
cout<<i<<" "<<x<<endl;
}
}
return 0;
}
或
#include <iostream>
using namespace std;
int main()
{
int s,i,x,n,e,six,nine;
for(s=1;s<10;s++)
for(i=0;i<10;i++)
for(x=0;x<10;x++)
for(n=1;n<10;n++)
for(e=0;e<10;e++)
{
six=_____________; // (3)
nine=_____________; // (4)
if(_____________) // (5)
cout<<six<<" "<<nine<<endl;
}
return 0;
}
11.马克思手稿中的数学题
This program is to solve an interesting math question in Karl Marx's manuscript.The Problem is as follows: 30 persons spent 50 yuan in a restaurant, amony them, each man spent 3 yuan, each woman spent 2 yuan, and each child spent 1 yuan. The question is how many men, women and children are there?
#include <iostream>
using namespace std;
int main()
{
int x,y,z;
cout<<"Men Women Children"<<endl;
for(x=0;x<=10;x++)
{
________________; // (1)
________________; // (2)
if(__________________________) // (3)
cout<<x<<" "<<y<<" "<<z<<endl;
}
return 0;
}
12.百钱百鸡问题
This program is to solve Problem of Hundred Yuan Hundred Fowls.Which is presented by Zhang Qiujiang, a Chinese ancient mathematician, in his work Bible of Calculation: 5 Yuan can buy 1 cock,3 Yuan can buy 1 hen, 1 Yuan buy 3 chickens, now one has 100 Yuan to buy 100 fowls, the question is how many cocks, hens, chickens to buy?
#include <iostream>
using namespace std;
int main()
{
int x,y,z;
for(x=0; _____________;x++) // 外层循环控制鸡翁数x (1)
for(y=0; _____________;y++) // 内层循环控制鸡母数y (2)
{
z=100-x-y;
if(_____________) // (3)
cout<<"cock="<<x<<", hen="<<y<<", chicken="<<z<<endl;
}
return 0;
}
13.三色球问题
This program is to solve Problem of Three Color Ball.The Problem is as follows: There are 12 balls in the pocket.Amony them, 3 balls are red,3 balls are white and 6 balls are black. Now take out any 8 balls from the pocket,how many color combinations are there?
#include <iostream>
using namespace std;
int main()
{
int i,j,cnt=0;
cout<<"RED WHITE BLACK"<<endl;
for(i=0; _____________;i++) // (1)
for(j=0; _____________;j++) // (2)
if(_____________) // (3)
cout<<++cnt<<" : "<<i<<" "<<j<<" "<<8-i-j<<endl
return 0;
}
14.配对新郎和新娘
This program is to solve Problem of Bridegroom and Bride.The Problem is as follows: Someone goes to 3 couples lovers'wedding. The bridegrooms are A,B,C and the brides are X,Y,Z. He wants to know who marries who and asks them. A says he will marry to X, X says her fiance is C, C says he will marry to Z. The man knows that they are all kidding. What they said is not true. So try to find who will marry to who?
#include <iostream>
using namespace std;
int main()
{
int x,y,z;
for(x=1;x<=3;x++) // 穷举x的全部可能配偶
for(y=1;y<=3;y++) // 穷举y的全部可能配偶
for(z=1;z<=3;z++) // 穷举z的全部可能配偶
if(x!=1&&x!=3&&z!=3&&x!=y&&x!=z&&y!=z)
{
cout<<" X will marry to "<<char(_____________)<<endl; // (1)
cout<<" Y will marry to "<<char(_____________)<<endl; // (1)
cout<<" Z will marry to "<<char(_____________)<<endl; // (1)
}
return 0;
}
15.邮票组合
This program is to solve Problem of Stamp Combination.The Problem is as follows. John has 4 stamps with value of 3 cents and 3 stamps with value of 5 cents. Use one or more of these stamps, how many kinds of postages can John provide?
#include <iostream>
using namespace std;
int main()
{
int i,j,s,n=0,a[28]={0};
for(i=0;i<=4;i++)
for(j=0;j<=3;j++)
{
____________; // (1)
if (____________) { a[s]=1; n++; } // (2)
}
cout<<"There are "<<n-1<< " kinds of postages: ";
for (i=1;i<=27;i++)
if (____________) cout<<i<<" "; // (3)
cout<<endl;
return 0;
}
参考答案:
1.(1)break (2)i<n (3)a+i*2
2.(1)break (2)n%2==1 (3)n!=1
3.(1)break (2)number==i*i+j*j+k*k+l*l
4.(1)b=0,i=1 (2)m=0,i=1 (3)m==a
5.(1)(mul/=10)>0 (2)number==mul
6.(1)a=n/100 (2)b=n%100
7.(1)x0=x1 (2)x1=cos(x0)
8.(1)n=i*i (2)b=n/10%10
9.(1)y=y*10+x%10 (2)x=x/10
10.(1)i=i+2 (2)a==b && c==d (3)s*100+i*10+x
(4)n*1000+i*100+n*10+e (5)3*six==2*nine
11.(1)y=20-2*x (2)z=30-x-y (3)3*x+2*y+z==50
12.(1)x<=20 (2)y<=33 (3)z%3==0&&5*x+3*y+z/3==100
13.(1)i<=3 (2)j<=3 (3)(8-i-j)<=6
14.(1)'A'+x-1 (2)'A'+y-1 (3)'A'+z-1
15.(1)s=i*3+j*5 (2)a[s]==0 (3)a[i]==1