Codeforces Round #109 (Div. 1) B number theory

Source: Internet
Author: User

Two numbers if it's not coprime, then they must have a prime factor.
Use VEC to deposit all prime-number factors from 2 to n
Whether the number of the factor is read in by the Vis
Only need to maintain the VIS array on the line when processing
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace Std;
const int MAXN = 100010;
Vector<int> VEC[MAXN];
int ISP[MAXN];
int VIS[MAXN];
int NUM[MAXN];
void Set ()
{
memset (ISP, 0, sizeof (ISP));
ISP[1] = 1;
for (int i = 2;i < MAXN; i + = 2)
{
Isp[i] = 1;
Vec[i].push_back (2);
}
for (int i = 3;i < MAXN; i++)
{
if (Isp[i]) continue;
for (int j = I;j < MAXN; j+=i)
{
ISP[J] = 1;
Vec[j].push_back (i);
}
}
}
int main ()
{
Freopen ("Input.txt", "R", stdin);
Set ();
int n, m;
Char Ch;int i;
while (~SCANF ("%d%d", &n, &m))
{
memset (num, 0, sizeof (num));
memset (Vis, 0, sizeof (VIS));
while (m--)
{
scanf ("%c%c%d", &ch, &ch, &i);
cout<<ch<<endl;
if (ch = = '-')
{
cout<<i<<endl;
if (!num[i]) puts ("already off");
Else
{
Puts ("Success");
Num[i] = 0;
for (int j = 0;j < Vec[i].size (); j + +)
VIS[VEC[I][J]] = 0;
}
}
if (ch = = ' + ')
{
if (Num[i]) puts ("already on");
Else
{
int flag = 0;
for (int j = 0;j < Vec[i].size (); j + +)
{
int t = vec[i][j];
if (Vis[t])
{
printf ("Conflict with%d\n", vis[t]);
flag = 1;
Break
}
}
if (!flag)
{
Puts ("Success");
cout<<i<<endl;
Num[i] = 1;
for (int j = 0;j < Vec[i].size (); j + +)
VIS[VEC[I][J]] = i;
}
}
}
}
}
return 0;
}







































































Codeforces Round #109 (Div. 1) B number theory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.