codeforce.C. Primitive Primes


题意:


给出两个多项式,使两个多项式相乘,得到的多项式,存在系数不被p整除,则输出这个系数所在项的次幂。


思路:


其实读懂题意,很好做。因为想得到系数不能整除p,那
么两个项都不能整除p,那我们只要找到a里面不能整除p的,再找到b里面不能整除p的,就可以输出两项的次幂和了

#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
    ios::sync_with_stdio(false); 
	cin.tie(0);
 
    int n, m, p;
    while (cin >> n >> m >> p) 
	{
        int ia = -1, ib = -1;
        for (int i = 0, a; i < n; i++) 
		{
            cin >> a;
            if (a % p && ia < 0) 
			{
                ia = i;
            }
        }
        for (int i = 0, b; i < m; i++) 
		{
            cin >> b;
            if (b % p && ib < 0) 
			{
                ib = i;
            }
        }
        cout << ia + ib << endl;
    }
    return 0;
}
···
发布了107 篇原创文章 · 获赞 3 · 访问量 7092

猜你喜欢

转载自blog.csdn.net/qq_43504141/article/details/104681037
今日推荐