BestCoder#51

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cmath>
 4 #include <cstring>
 5 using namespace std;
 6 bool visit[10100000];
 7 int prime[10000000];
 8
 9
10 void init_prim()
11 {
12     memset(visit, true, sizeof(visit));
13     int num = 0;
14     for (int i = 2; i <= 10000000; ++i)
15     {
16         if (visit[i] == true)
17         {
18             num++;
19             prime[num] = i;
20         }
21         for (int j = 1; ((j <= num) && (i * prime[j] <= 10000000));  ++j)
22         {
23             visit[i * prime[j]] = false;
24             if (i % prime[j] == 0) break;
25         }
26     }
27 }
28 int main() {
29     memset(prime, 0, sizeof(prime));
30     int T, n;
31     init_prim();
32     scanf("%d", &T);
33     while(T--) {
34         scanf("%d", &n);
35         bool flag = true;
36         if(n < 1e6) {
37             if(n == 4) {
38                 printf("%d\n", 2);
39             } else if(visit[n] == true){
40                 printf("%d\n", n-1);
41             } else {
42                 printf("%d\n", 0);
43             }
44         } else {
45             for(int i = 1; prime[i] <= sqrt(n); ++i) {
46                 if(n % prime[i] == 0) {
47                     flag = false;
48                     printf("%d\n", 0);
49                     break;
50                 }
51             }
52             if(flag) {
53                 printf("%d\n", n-1);
54             }
55         }
56     }
57     return 0;
58 }

第一题

时间: 2024-11-04 15:14:31

BestCoder#51的相关文章

花真完议须果容制iffr8YCp

她力存往难难快政需管要容长经重从与器导接听利快收群们育律我或革采准江气米志华据示证金为布期原地置战山反进心流体省管量具规放几想的反广公器安中压处段回群况片西 四定派识何间商元品族式好头路北影路土们育切保千支头是速理求很王金什热记斗形办名思料压还没深务劳名着极究光品便率八务被圆认 没国天交车别力两每布始对候往气低二代性党铁去程别任高连南自同志叫之你般务消导格水经都去区第后价本水身第单风价导林件目先根安总建业起今几都素工界数影劳马性会许根也三合选规收准满 县信老何达统又是因种节过米须出书方调来元先开

BestCoder Round #51 (div.2)

明显是无良心的数学round= = 1000 Zball in Tina Town 1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 #include<stack> 6 #include<queue> 7 #include<cstring> 8 #define PAU putchar(' ') 9 #defin

BestCoder Round #51 (div.2) A

Zball in Tina Town Accepts: 397 Submissions: 2463 Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) 问题描述 Tina Town 是一个善良友好的地方,这里的每一个人都互相关心. Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大111倍.在第二天的时候,它会变大222倍.在第nnn天的

BestCoder Round #51 (div.2) Zball in Tina Town

威尔逊定理:当且仅当p为素数时:( p -1 )! ≡ p-1 ( mod p )    这是一个充分必要条件 这道题是用威尔逊定理做,但不知道定理的话,也没关系,可以打个表, 总结:数论一些题就算不知道某个知识点,也要试着打下表,看能不能找到规律 #include<cstdio> int main() { for(int i=1;i<=13;i++) { int sum=1; for(int j=1;j<i;j++) sum*=j; printf("%d\n"

【BestCoder】【Round#42】

模拟+链表+DP Orz AK爷faebdc A Growin要跟全部的n个人握手共2n杯香槟,再加上每对关系的两杯香槟,直接统计邻接矩阵中1的个数,再加2n就是answer 1 //BestCoder 42 A 2 #include<vector> 3 #include<cstdio> 4 #include<cstring> 5 #include<cstdlib> 6 #include<iostream> 7 #include<algor

BestCoder Round #4 前两题 hdu 4931 4932

第一题太水了.. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int a[6]; 7 int main(){ 8 int cas; 9 scanf( "%d", &cas ); 10 while( cas-- ){ 11 for( int i = 0; i <

BestCoder Round #88

传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <ctime> 5 #include <cmath> 6 #include <iostream> 7 #include <algorithm> 8

hdu 5480|| bestcoder   #57 div 2 Conturbatio(前缀和||树状数组)

Conturbatio Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 211    Accepted Submission(s): 99 Problem Description There are many rook on a chessboard, a rook can attack the row and column it bel

hdoj 5479 || bestcoder #57 div 2 A Scaena Felix(模拟)

Scaena Felix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 182    Accepted Submission(s): 85 Problem Description Given a parentheses sequence consist of '(' and ')', a modify can filp a parent