【问题描述】
输入一个整数,判断其能否被3、5、7整除,若:
(1)能同时被3,5,7整除,则输出It's divisible by 3,5,7;
(2)能被其中两数(要指出哪两个)整除(如能被3,7整除),则输出It's divisible by 3,7;
(3)能被其中一个数(要指出哪一个)整除(如能被3整除),则输出It's divisible by 3;
(4)不能被3,5,7任一个整除,则输出null。
【输入形式】
输入一个整数n。
【输出形式】
输出一个判断信息,表示答案。
【样例输入】
30
【样例输出】
It's divisible by 3,5
【样例说明】
30能被3和5整除,但是不能被7整除。
【用例规模与约定】
所有评测用例满足:-1000000 ≤ n ≤ 10000000。
#include<iostream>
using namespace std;
int main()
{
int a;
cin>>a;
int j=2;
for(int i=3;i<=7;i+=2)
{
if(a%i==0)
{
j*=i;
}
}
if(j==2)
{
cout<<"null"<<endl;
}
else if(j==6)
{
cout<<"It's divisible by 3"<<endl;
}
else if(j==10)
{
cout<<"It's divisible by 5"<<endl;
}
else if(j==14)
{
cout<<"It's divisible by 7"<<endl;
}
else if(j==30)
{
cout<<"It's divisible by 3,5"<<endl;
}
else if(j==42)
{
cout<<"It's divisible by 3,7"<<endl;
}
else if(j==70)
{
cout<<"It's divisible by 5,7"<<endl;
}
else if(j==210)
{
cout<<"It's divisible by 3,5,7"<<endl;
}
system("pause");
return 0;
}