原网址:https://blog.csdn.net/weixin_43381566/article/details/108867034
第十一届蓝桥杯省赛C/C++大学B组 试题I
没有那么复杂的数学式子。不用用数学原理。
然后原文的代码不对,我给改了下,这样所有的测试样例都能通过。
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n = 0;
int K = 0;
int nums = 0;
cin >> n;
cin >> K;
vector<int> v(n,0);
for(int i = 0; i < n ; ++i)
{
int key = 0;
cin >> key;
v[i] = key;
}
string s1 = "";
for(int i =0 ; i < n ; ++i)
{
for(int j = 0; j < n ; j++)
{
if(i != j)
{
s1 = to_string(v[i]) + to_string(v[j]);
if(stoi(s1) % K == 0)
{
nums++;
}
}
}
}
cout << nums << endl;
return 0;
}