Euler's formula (plane)

Euler's formula is expressed like this V+FE = 2, V represents the number of points, F represents the number of faces, and E represents the number of edges

 

A question for the Xinjiang regional competition, cool...

Farmer John owns a farm. He first builds a circle fence. Then, he will choose n points and build some straight fences connecting them. Next, he will feed a cow in each region so that cows cannot play with each other without breaking the fences. In order to feed more cows, he also wants to have as many regions as possible. However, he is busy building fences now, so he needs your help to determine what is the maximum number of cows he can feed if he chooses these n points properly.

Input

The first line contains an integer 1≤T≤1000001 \le T \le 1000001T100000, the number of test cases. For each test case, there is one line that contains an integer n. It is guaranteed that 1≤T≤1051 \le T \le 10^5 1T105 and 1≤n≤10181 \le n \le 10^{18}1n1018.

Output

For each test case, you should output a line ”Case #iii: ans” where iii is the test caseS number, starting from 111 and ans is the remainder of the maximum number of cows farmer John can feed when divided by 109+710^9 + 7109+7.

sample input

3
1
3
5

Sample output

Case #1: 1
Case #2: 4
Case #3: 

Question 16 Meaning: Given n points, any two points can be connected by a line, how many pieces can the plane be divided into at most?
You can directly apply an Euler formula, calculate the points and edges, and the surface can be directly derived, but the final answer is to subtract 1, because the periphery of the plane is an infinite surface.
The idea is to start from any point, enumerate straight lines, enumerate 0 points on the left of the first straight line, and n-2 points on the right, obviously there will be no intersection on this straight line, enumerate the second straight line, on the left A point, n-2-1 points on the right, will generate 1*(n-2-i) points on the straight line to
accumulate and calculate, and the same is true when calculating the sides.

From V + F - E = 2, F+1 = E - V + 2

Substitution Simplification

Code example:

#define ll unsigned long long
const ll mod = 1e9+7;

ll n;

ll qpow(ll x, ll p){
    ll res = 1;
    
    while(p > 0){
        if (p&1) res *= x;
        res% = mod;
        x *= x;
        x% = mod;
        p >>= 1;
    }
    return res%mod;
}

ll solve(){
    ll s1 = 1;
    for(int i = 1; i <= 4; i++){
        s1 *= n;
        s1% = mod;
    }
    ll s2 = 1;
    for(int i = 1; i <= 3; i++){
        s2 *= n;
        s2% = mod;
    }
    s2 *= 6;  
    s2 %= mod; // !!! Because WA has been done several times here, otherwise there will be problems with subtraction and modulo
    ll s3 = 1;
    for(int i = 1; i <= 2; i++){
        s3 * = n;
        s3% = mod;
    }
    s3 *= 23;
    s3% = mod;
    ll s4 = 18*n%mod;
    
    ll s = ((s1-s2 + mod)% mod + (s3-s4 + mod)% mod)% mod;
    ll f = qpow(24, mod-2)%mod;
    ll ans = ((s*f)%mod+1)%mod;
    return ans;
}

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int t;
    int case = 1;
    
    cin >>t;
    while(t--){
        scanf("%llu", &n);
        n% = mod;
        printf("Case #%d: ", kase++);
        if (n == 1) printf("1\n");
        else if (n == 2) printf("2\n");
        else if (n == 3) printf("4\n");
        else printf("%llu\n", solve());    
    }
    return 0;
}

 

 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324893012&siteId=291194637