1. 程式人生 > >CodeForces 26 A.Almost Prime(數論)

CodeForces 26 A.Almost Prime(數論)

Description

1~n中有多少數字只有兩個不同的素因子

Input

一個正整數n(1n3000)

Output

輸出1~n中只有兩個不同的素因子的數字個數

Sample Input

10

Sample Output

2

Solution

簡單題,暴力判即可

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map> #include<set> #include<ctime> using namespace std; typedef long long ll; typedef pair<int,int>P; const int INF=0x3f3f3f3f,maxn=3005; int num[maxn]; int check(int n) { int cnt=0; for(int i=2;i*i<=n;i++) if(n%i==0) { cnt++; while
(n%i==0)n/=i; } if(n>1)cnt++; if(cnt==2)return 1; return 0; } void init(int n=3000) { for(int i=1;i<=3000;i++) { num[i]=num[i-1]; if(check(i))num[i]++; } } int main() { init(); int n; while(~scanf("%d",&n))printf("%d\n",num[n]); return
0; }

相關推薦

CodeForces 26 A.Almost Prime數論

Description 問1~n中有多少數字只有兩個不同的素因子 Input 一個正整數n(1≤n≤3000) Output 輸出1~n中只有兩個不同的素因子的數字個數 Sample Inp

Border Codeforces Round #499 (Div. 2) 數論

E. Border time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ast

Codeforces VK Cup Finals #424 Div.1 A. Office KeysDP

class clu define codeforce -a off blog ffi color   顯然是不可能交叉取鑰匙的,於是把鑰匙和人都按坐標排序就可以DP了   鑰匙可以不被取,於是f[i][j]表示前i個鑰匙被j個人拿的時間   f[i][j]=min(f[

Codeforces 558E A Simple Task權值線段樹

else 小寫字母 putc ask ref href while += brush 題目鏈接 A Simple Task 題意 給出一個小寫字母序列和若幹操作。每個操作為對給定區間進行升序排序或降序排序。 考慮權值線段樹。 建立26棵權值線段樹。每次操作的

2018.10.26 bzoj2721: [Violet 5]櫻花數論

傳送門 推一波式子: 1 x +

2018.10.26 poj3421X-factor Chains數論+排列組合

傳送門 排列組合入門題。 令 X = p

Newcoder 110 A.最大乘積數論

Description 這題要你回答 T T T個詢問,給你一個正整數

Codeforces 955C Sad powers數論

Codeforces 955C Sad powers 題意 q組詢問,每次詢問給定L,R,求[L,R]區間內有多少個數可以寫成ap的形式,其中a>0,p>1,1 ≤ L ≤ R ≤ 1e18。 思路 對於p>2的情況,由於隨著指數p的增大,小於1e18的p次冪的數量會急劇減

D - Undoubtedly Lucky Numbers CodeForces - 244B數論

Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) co

CodeForces 659 A. Round House簡單數學推理

傳送門 A. Round House time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output V

codeforces 900D Unusual Sequences 數論

Note There are three suitable sequences in the first test: (3, 3, 3), (3, 6), (6, 3). There are no suitable sequences in the second test. 題意:給出 x,y 讓求

codeforces 901B GCD of Polynomials 數論+構造

Note In the second example you can print polynomials x2 - 1 and x. The sequence of transitions is (x2 - 1, x) → (x,  - 1) → ( - 1, 0). There are two st

數論進位制轉換二a進位制換成b進位制

  數制轉換這類題解法很固定,常見的就兩種,昨天是第一種,今天是第二種。 題目:進位制轉換 時間限制:1 秒 記憶體限制:32 兆 題目描述:     求任意兩個不同進位制非負整數的轉換(2進位制~16進位制),所給整數在long所能表達的範圍之內。     不同進位制的表

hdu 1792 A New Change Problem數論

A New Change Problem Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1236    A

Codeforces 933 A. A Twisty Movement dp

Description A dragon symbolizes wisdom, power and wealth. On Lunar New Year’s Day, people model a

牛客多校第一場A——Monotonic Matrix數論——組合數學—— Lindström–Gessel–Viennot lemma

這題在打比賽時,我感覺到了來自於世界的惡意。。。 Lindström–Gessel–Viennot lemma定理,在比賽前,我是完全沒有聽說過的,好想哭,掛機的數論選手。。。 1. Count the number of n x m matrices A satisfyi

Codeforces Round #489 (Div. 2) B. Nastya Studies Informatics 數論

Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks mom

poj3292——Semi-prime H-numbers數論

Description This problem is based on an exercise of David Hilbert, who pedagogically suggested that one study the theory of 4n+1 n

UVA 10042 Smith Numbers數論

sizeof ret col 保存 進行 uva nal isp published Smith Numbers Background While skimming his phone directory in 1982, Albert Wilansky, a ma

[luoguP1069] 細胞分裂數論

def getc urn ostream lin 優先級 org return 優先 傳送門 分解質因數,不說了 這題坑了我2個多小時 教訓 不熟悉位運算的優先級一定要加括號!!!! #include <cstdio> #include &