Topic Description The husband is interested in a number of digits one day, but he doesn't want to be like a man,
So he wanted to know to give an integer n, beg n! The number of bits in the 8 binary. Input Description:
The first line is an integer t (0<t<=1000000) (representing the T-group data)
Next T line, each line has an integer n (0<=n<=10000000)
Output Description:
Output n! The number of digits in the 8 binary.
Example 1 input
3425
Output
213
Idea: Sterling formula.
The Sterling formula (Stirling ' s approximation) is a mathematical formula for the approximation of the factorial of N, seeking n! Number of digits:
LNN!=NLNN-N+0.5*LN (2*N*PI)! If you want to ask for the number of people, he will be replaced by a 10 base. The LOG10N!=LNN!/LN10=N*LG (n/e) +lg (sqrt (2*N*PI)) is obtained by using the bottom-changer formula. Bashi sub-cosmetic and 1 is the number of digits!
Code:
1 //#include "bits/stdc++.h"2#include"Cstdio"3#include"Map"4#include"Set"5#include"Cmath"6#include"Queue"7#include"Vector"8#include"string"9#include"CString"Ten#include"time.h" One#include"iostream" A#include"stdlib.h" -#include"algorithm" - #defineDB Double the #definell Long Long - #defineVEC vector<ll> - #defineMt vector<vec> - #defineCI (x) scanf ("%d", &x) + #defineCD (x) scanf ("%lf", &x) - #defineCL (x) scanf ("%lld", &x) + #definePi (x) printf ("%d\n", X) A #definePD (x) printf ("%f\n", X) at #definePL (x) printf ("%lld\n", X) - #defineINF 0x3f3f3f3f - #defineRep (i, X, y) for (int i=x;i<=y;i++) - Const intN = 1e6 +5; - Const intMoD = 1e9 +7; - Const intMoD = mod-1; in ConstDB EPS = 1e-Ten; - ConstDB PI = ACOs (-1.0); to using namespacestd; + ConstDB e=2.71828182845; - intMain () the { * ll T,n; $ cl (t);Panax Notoginseng while(t--) - { thell ans=1; + cl (n); A if(n>3){ theAns= (n (log10 (db) n/e) +log10 (sqrt ((db)2.0*N*PI))/log10 (8)+1; + } - Pl (ans); $ } $ return 0; -}
D Calf vs. Small Guest
Title DescriptionThe calf and the small guest play The stone game, they use n a stone to surround a circle, the calf and the small passenger respectively from which takes the stone, who first takes out who wins, each can take one or adjacent two from one lap, each time is the calf first takes, please output winner's name (calf wins output Xiaoniu, the small guest wins output Xiaoke) 2 3 4 take away 2 13 not adjacent)
Input Description:
Input includes multiple sets of test data
One n (1≤n≤1e9) per set of test data
Output Description:
Each group outputs the winner's name in one line (calf wins output Xiaoniu, small guest wins output Xiaoke)
Example 1 input
23
Output
Xiaoniuxiaoke
Idea: Game topic, take stone (seven) problem.
Idea: Assuming that the number of stones equals 5, if first take one, then the latter take two, the remaining two stones into two piles, the latter win. If the first person takes two, then the latter takes one to divide the remaining two stones into two piles, the latter winning.
Assuming that the number of stones equals 6, if first take one, then the latter take one, the remaining stones are divided into two segments, each two, if the first person to take two, then the latter win, if the first person to take one, then the latter to take another one, so that the remaining two stones are divided into two piles, the latter win. If the first one takes two, the latter also takes two to make the remaining two stones into two piles, the latter winning.
So the yourselves take away, the latter take one or two, the remaining stones are divided into symmetrical two paragraphs, and so on, if the number of stones greater than 2 the latter must win.
Code:
1#include <stdio.h>2 3 intMain (void) 4 { 5 intN; 6 while(SCANF ("%d", &n)! =EOF)7 { 8 if(N >2) 9printf"xiaoke\n"); Ten Else Oneprintf"xiaoniu\n"); A } - return 0; -}
G: Flood problem
Given a number n, ask 1 to N, how many numbers are not multiples of 2 5 11 13. Input Description:
There are multiple sets of inputs
One number per line n,1<=n<=10^18.
Output Description:
The output output of each row is not a multiple of 2 5 11 13.
Example 1input theOutput4Description1 3 7 9
Ideas:
The principle of repulsion: To calculate the size of several sets of merge sets, we will first calculate the size of all the individual collections, then subtract all the parts that intersect all two sets, add the parts that intersect all of the three sets, subtract the parts that intersect all of the four sets, and so on, and always calculate to the part where all the collections intersect.
Code:
1#include <map>2#include <vector>3#include <queue>4#include <cstdio>5#include <cstdlib>6#include <cstring>7#include <iostream>8#include <algorithm>9#include <cmath>Ten #defineMAXN 100010 One using namespacestd; AtypedefLong Longll; - #definePI ACOs (-1.0) - intMain () the { - ll N; -Ios::sync_with_stdio (false); - while(SCANF ("%lld", &n)! =EOF) + { - ll CNT; +cnt=n-(n/2)-(n/5)-(n/ One)-(n/ -); Acnt=cnt+ (n/Ten) + (n/ A) + (n/ -) + (n/ -) + (n/ $) + (n/143); atcnt=cnt-(n/ the)-(n/ the)-(n/715)-(n/286); -cnt=cnt+ (n/1430); -cout<<cnt<<Endl; - } - return 0; -}
F:
Title Description
A total of n heap of stones, known to the number of stones in each heap, two people take the stones in turn, each time can only select a heap of n heap stones to take a certain number of stones (at least one), after the son, you can also be the gravel of the remaining stones randomly selected to be placed on any other heap or several piles. Waiting for someone who can't take the midnight show that the person lost the game. Note: After a heap of stones has no children, it is no longer possible to place stones here.
Let's say that every time a calf takes a pebble, and both sides are absolutely smart, now give you the number of stones and the number of stones per heap, and determine if the Mavericks will win.
Input Description:
There may be multiple sets of test data (no more than 1000 test data groups)
The first line of each set of test data is an integer representing N (1<=n<=10)
The second line is n integers representing the number of stones in the heap. (the number of stones per heap is not more than 100)
When the input n is 0 o'clock, the input ends
Output Description:
For each set of test data, the output of WIN indicates that the calf can win, and the output lose indicates that the calf will fail.
Example 1 input
32 1 321 10
Output
Winlose
Idea: If there is only a heap of stones, then the initiator will win. If there are two piles of the same number of stones, it is obvious that the initiator is defeated, because the opponent only needs symmetrical operation.
Similarly, if the stone can be divided into two groups, the corresponding heap of stone number is equal, such as {1,2,3,1,2,3}, the initiator will also be defeated, so the number of the same two piles can be temporarily not considered.
If there are two piles of different stones, the initiator can make the same number, the initiator will win.
If there are three piles of different stones, the initiator can choose the largest pile of operations, remove the part, so that the remaining stones just filled the gap between the remaining two, the initiator win. And so on, the initiator will fail and only when the initial stone number is {1,2,3,1,2,3} this type.
Code:
1#include <stdio.h>2 intstack[ the],c[ the];3 intMain ()4 {5 intN;6 while(SCANF ("%d", &n)! =EOF)7 {8 if(n==0)return 0;9 for(intI=1; i<=n;i++) scanf ("%d",&c[i]);Ten for(intI=1; i<=n-1; i++) One for(intj=i+1; j<=n;j++) A if(c[i]>C[j]) - { - inttmp=C[i]; thec[i]=C[j]; -c[j]=tmp; - } - intt=0; + for(intI=1; i<=n;i++) - { + if(t==0) stack[++t]=C[i]; A Else at { - if(Stack[t]==c[i]) t--; - Elsestack[++t]=C[i]; - } - } - if(t==0) printf ("0\n"); in Elseprintf"1\n"); - } to return 0; +}
2018 National multi-school algorithm winter training