Codeforces Round #319 (Div. 2) C Vasya and Petya's Game

因为所有整数都能被唯一分解,p1^a1*p2^a2*...*pi^ai,而一次询问的数可以分解为p1^a1k*p2^a2k*...*pi^aik,这次询问会把所有a1>=a1k && a2 >= a2k &&...

a3 >= a3k的数从原来的集合中分开。ai表示pi的幂。

那么只有当这个数的素因子的最大幂都被询问过一次,这个数才能确定。因此答案是所有的不大于n的只有一个素因子的数。

#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e3+5;
int prime[maxn];
bool vis[maxn];
int sieve(int n)
{
    int m = sqrt(n+0.5);
    for(int i = 2; i <= m; i++) if(!vis[i]){
        for(int j = i*i; j <= n; j+=i) vis[j] = true;
    }
    int c = 0;
    for(int i = 2; i <= n; i++) if(!vis[i]){
        prime[c++] = i;
    }
    return c;
}

vector<int> ans;
int main()
{
    int tot = sieve(1000);
    int n; scanf("%d",&n);
    for(int i = 0; i < tot; i++){
        int p = prime[i];
        if(p > n) break;
        for(int t = p; t<=n; t*=p){
            ans.push_back(t);
        }
    }
    printf("%d\n",ans.size());
    for(int i = 0; i < ans.size(); i++){
        if(i) putchar(‘ ‘);
        printf("%d",ans[i]);
    }
    return 0;
}

Codeforces Round #319 (Div. 2) C Vasya and Petya's Game

时间: 2024-10-31 23:13:35

Codeforces Round #319 (Div. 2) C Vasya and Petya's Game的相关文章

Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)

题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put o

Codeforces Round 319 # div.1 &amp; 2 解题报告

Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1<=x<=10^9 题解: 送分题…对于每一行,判断是否存在数x即可…也可以枚举x的因子判断是否出现在表内… #include<cstdio>#include<cstring>inlineint read(){int s =0;char c;while((c=getchar())

codeforces水题100道 第十五题 Codeforces Round #262 (Div. 2) A. Vasya and Socks (brute force)

题目链接:http://www.codeforces.com/problemset/problem/460/A题意:Vasya每天用掉一双袜子,她妈妈每m天给他送一双袜子,Vasya一开始有n双袜子,请问第几天的时候Vasya会没有袜子穿?C++代码: #include <iostream> using namespace std; int n, m; int main() { cin >> n >> m; int d = 0; while (n) { d ++; if

Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力

A. Vasya and Football Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red

Codeforces Round #281 (Div. 2) C. Vasya and Basketball 排序

C. Vasya and Basketball Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from does

Codeforces Round #281 (Div. 2) B. Vasya and Wrestling 水题

B. Vasya and Wrestling Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, th

Codeforces Round #281 (Div. 2) D. Vasya and Chess 博弈

D. Vasya and Chess Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is

Educational Codeforces Round #54 (Div. 2) E. Vasya and a Tree 技巧題

題目連接:http://codeforces.com/contest/1076/problem/E 本題大意: 給一棵根節點為"1"樹,給m個操作,每個操作三個整數,v,d,x,意思是從節點1,往下深度d,遍及的節點的值都加上x,d可能是0,就是只加在自己上.結束m個操作后輸出每個節點的值. 解題思路: 這裡不應該考慮同時操作整棵樹.因為每個節點的子樹是多樣的,而應該以dfs的形式,直接搜到葉子節點,這樣沿途就是一條鏈.每時每刻都在操作一條鏈,也就是一段區間.這樣操作轉化為:一個節點往

Codeforces Round #319 (Div. 2) D

E A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u andv the condition