Luogup4132 [bjoi2012] cannot calculate the equality Number Theory

Source: Internet
Author: User

Portal

Previous questions

During the training, the teacher told jokes together.

This question first look for a regular table on the guess is P-1) * (q-1)/4

Without a set of Sigma, the formula is first divided into two (in fact, the same)

Then consider each item before the subsummation.

For each K, the result is an integer in Y = Q/P * X.

Then the other side is the complementary side.

(The two parts of this formula are the integral points of the two parts divided by the main diagonal line of a square chart ([p/2], [q/2]) [], indicating the rounded down

The figure is about long.

Since p and q are prime numbers, only when they are equal will there be less P points (Boundary)

Code:

 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<queue> 5 #define ms(a,b) memset(a,b,sizeof a) 6 #define rep(i,a,n) for(int i = a;i <= n;i++) 7 #define per(i,n,a) for(int i = n;i >= a;i--) 8 #define inf 1000000007 9 using namespace std;10 typedef long long ll;11 typedef double D;12 #define eps 1e-813 ll read() {14     ll as = 0,fu = 1;15     char c = getchar();16     while(c < ‘0‘ || c > ‘9‘) {17         if(c == ‘-‘) fu = -1;18         c = getchar();19     }20     while(c >= ‘0‘ && c <= ‘9‘) {21         as = as * 10 + c - ‘0‘;22         c = getchar();23     }24     return as * fu;25 }26 //head27 ll p,q,ans;28 int main() {29     p = read(),q = read();30     ans = (p>>1)*(q>>1);31     if(p == q) ans += p>>1;32     printf("%lld\n",ans);33     return 0;34 }
View code

 

Luogup4132 [bjoi2012] cannot calculate the equality Number Theory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.