Skip to main content
  1. Posts/

codeforces #319 C - Vasya and Petya's Game (数学)

·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

因为每一个正整数可以唯一分解质因数…

要看能猜多少次,只要知道不大于n的质因子数有多少个即可(相同的算多

由于n才是1000.所以素数表随便搞就好….不用筛也行…

 1/*************************************************************************
 2	> File Name: code/cf/#319/C.cpp
 3	> Author: 111qqz
 4	> Email: rkz2013@126.com
 5	> Created Time: 2015年09月18日 星期五 20时29分00秒
 6 ************************************************************************/
 7
 8#include<iostream>
 9#include<iomanip>
10#include<cstdio>
11#include<algorithm>
12#include<cmath>
13#include<cstring>
14#include<string>
15#include<map>
16#include<set>
17#include<queue>
18#include<vector>
19#include<stack>
20#include<cctype>
21#define y1 hust111qqz
22#define yn hez111qqz
23#define j1 cute111qqz
24#define ms(a,x) memset(a,x,sizeof(a))
25#define lr dying111qqz
26using namespace std;
27#define For(i, n) for (int i=0;i<int(n);++i)
28typedef long long LL;
29typedef double DB;
30const int inf = 0x3f3f3f3f;
31const int N=1E3+5;
32int pri[N];
33int cnt;
34int n;
35int ans[N];
36bool prime( int x)
37{
38    if (x<=3) return true;
39    for ( int i = 2 ; i *i <= x ; i++)
40    {
41	if (x%i==0) return false;
42    }
43    return true;
44}
45int main()
46{
47  #ifndef  ONLINE_JUDGE
48  //  freopen("in.txt","r",stdin);
49  #endif
50    ms(pri,0);
51    cnt  = 0 ;
52
53    for ( int i = 2 ; i <= 1005 ; i++)
54    {
55	if (prime(i))
56	{
57	    cnt++;
58	    pri[cnt] = i ;
59	}
60    }
61    scanf("%d",&n);
62    ms(ans,0);
63    int num = 0 ;
64    for ( int i = 1 ; pri[i] <= n&&i<=cnt ; i++)
65    {
66	int tmp = pri[i];
67	while (tmp<=n)
68	{
69	    num++;
70	    ans[num] = tmp;
71	    tmp = tmp * pri[i];
72
73	}
74    }
75    cout<<num<<endl;
76    for ( int i = 1 ; i <= num  ; i++)
77    {
78	cout<<ans[i]<<" ";
79    }
80
81
82
83 #ifndef ONLINE_JUDGE
84  fclose(stdin);
85  #endif
86	return 0;
87}

Related

(BC 一周年) hdu 5312 Sequence

·2 mins
比赛的时候没做出来.这道题需要用到的一个重要的性质是,任意一个自然数可以表示成至多三个三角形数(1,3,6,10,15…..)的和(orz高斯)然后也有推广到任意自然数可以表示成k个k角形数的和的结论(费马提出了猜想,柯西给了证明)然后官方题解说的比较好:

codeforces 535 C.Tavas and karafs (解方程)

·2 mins
http://codeforces.com/problemset/problem/535/C 题读了好几遍才读懂。 题意是给出一个等差数列,操作严格要求从最左边不为零的连续m个数减去1,最多执行t次后问离最左边最远的位置在哪里。 有两个限制条件…一个是本身的si不能大于t,否则无法吃完。 还有一个是从sl到sr的和不能超过m*t (比赛的时候考虑的不周到。。实际上只有当r-l+1比m大的时候才是m,也就是说要取min(m,l-r+1)) 这题正解应该是二分….直接Lower_bound。。。看到也有人用前缀和搞的。 我是解方程了(貌似是个傻逼做法)…. 可以列出一个关于r的一元二次方程。。。然后求根公式2333 方程是:

codeforces 534 C Polycarpus' Dice

·1 min
http://codeforces.com/problemset/problem/534/C 题意是说一共有N个骰子,第I个筛子一共有di面…现在知道这些骰子的点数之和,问对于每一个骰子不能取得值有多少个。

cf 534B. Covered Path

·1 min
http://codeforces.com/problemset/problem/534/B 题意是说一辆车,每秒内的速度恒定…第I秒到第I+1秒的速度变化不超过D。初始速度为V1,末速度为V2,经过时间t,问最远能走多远。

hdu 2138 How many prime numbers

ACM STEPS里的…这题前面一道是求LCM….结果接下来就是这么一道。。。 朴素会超….筛法会爆….题目顺序真是按照难度来的? 于是想到 Miller-Rabin素数测试……. 这个方法是基于费马小定理 我的理解就是… 如果我要判断n是否为素数 只要取k个数 如果满足 a^(n-1)mod n =1 那么n就很可能为素数。 证明什么的…暂时还是算了吧…论文里貌似扯了一大堆 第一次用,竟然真的A了。。。。 感觉更好的办法也许是先打一个比较小的素数表,然后每次random选取若干个进行判断…那样应该更可靠些? 本来想WA掉之后再改的。。。没想到这么写就A掉了。。。。杭电数据略水?