Topic Link http://acm.hdu.edu.cn/showproblem.php?pid=1337 Hangzhou Electric
http://poj.org/problem?id=1218 Tsinghua
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1350 Zhejiang
Originally thought that a small water problem is not worth summarizing, but found that there are many ways, good magic AH
Method One: The data is very small simulation is good
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h>using namespace Std;int A[110];int Main () { int t, N; scanf ("%d", &t); while (t--) { memset (a, 0, sizeof (a)); scanf ("%d", &n); for (int i=1, i<=n; i++) {for (int j=i; j<=n; j+=i) { a[j]=a[j]^1; } } int ans=0; for (int i=1; i<=n; i++) { if (a[i]==1) ans++; } printf ("%d\n", ans); } return 0;}
Method Two: In fact, the prisoner can escape is a regular follow, the door has two forms, as long as the total number of prisoners to open and close is odd, such as 3 1 open 3 off, the sum of the switch is even; for example, 4 1 open 2 off 4 open, the sum of the switch is odd is to see whether there are odd factors;
#include <iostream>#include<algorithm>#include<stdio.h>#include<string.h>using namespacestd;intSolveintx) { intCnt=0; for(intI=1; i<=x; i++) { if(x%i==0) CNT++; } if(cnt%2==0) return 0; Else return 1;}intMain () {intT, N; scanf ("%d", &t); while(t--) {scanf ("%d", &N); intans=0; for(intI=1; i<=n; i++) { if(Solve (i)) ans++; } printf ("%d\n", ans); } return 0;}
The Third kind: is to see others to know, really is the world of great wonders;
The principle is: only the complete square number can have an odd number of factors, such as 3, 9, so only need to ask for the total number of squares within n;
The number of complete squares within n =sqrt (n);
#include <cstdio> #include <cmath>int main () { int t,n; scanf ("%d", &t); while (t--) { scanf ("%d", &n); printf ("%d\n", (int) sqrt (n)); } return 0;}
HDU 1337 && POJ 1218&& zju 1350 Method Summary