在本文中,我们将给您介绍关于PythagoreanTriples的详细内容,并且为您解答CodeforcesRound#368(Div.2)+构建直角三角形的相关问题,此外,我们还将为您提供关于A.C
在本文中,我们将给您介绍关于Pythagorean Triples的详细内容,并且为您解答Codeforces Round #368 (Div. 2) + 构建直角三角形的相关问题,此外,我们还将为您提供关于A. Counterexample (Codeforces Round #275(div2)、B. Friends and Presents(Codeforces Round #275(div2)、B. Friends and Presents(Codeforces Round #275(div2)_html/css_WEB-ITnose、C. Book Reading (Codeforces Round #582 (Div. 3))的知识。
本文目录一览:- Pythagorean Triples(Codeforces Round #368 (Div. 2) + 构建直角三角形)(python编写直角三角形)
- A. Counterexample (Codeforces Round #275(div2)
- B. Friends and Presents(Codeforces Round #275(div2)
- B. Friends and Presents(Codeforces Round #275(div2)_html/css_WEB-ITnose
- C. Book Reading (Codeforces Round #582 (Div. 3))
Pythagorean Triples(Codeforces Round #368 (Div. 2) + 构建直角三角形)(python编写直角三角形)
题目链接:
https://codeforces.com/contest/707/problem/C
题目:
题意:
告诉你直角三角形的一条边,要你输出另外两条边。
思路:
我们容易发现除2外的所有素数x作为直角边,那么另外两条边的长度一定为(x * x - 1)/2和(x * x + 1)/2,因此对于每个数我们只需要找到n的最小素因子(除2外)即可,需要额外处理一下2的幂次。
代码实现如下:
1 #include <set> 2 #include <map> 3 #include <deque> 4 #include <queue> 5 #include <stack> 6 #include <cmath> 7 #include <ctime> 8 #include <bitset> 9 #include <cstdio> 10 #include <string> 11 #include <vector> 12 #include <cstdlib> 13 #include <cstring> 14 #include <iostream> 15 #include <algorithm> 16 using namespace std; 17 18 typedef long long LL; 19 typedef pair<LL,LL> pLL; 20 typedef pair<LL,int> pLi; 21 typedef pair<int,LL> pil;; 22 typedef pair<int,int> pii; 23 typedef unsigned long long uLL; 24 25 #define lson rt<<1 26 #define rson rt<<1|1 27 #define lowbit(x) x&(-x) 28 #define name2str(name) (#name) 29 #define bug printf("*********\n") 30 #define debug(x) cout<<#x"=["<<x<<"]" <<endl 31 #define FIN freopen("D://code//in.txt","r",stdin) 32 #define IO ios::sync_with_stdio(false),cin.tie(0) 33 34 const double eps = 1e-8; 35 const int mod = 1000000007; 36 const int maxn = 2e5 + 7; 37 const double pi = acos(-1); 38 const int inf = 0x3f3f3f3f; 39 const LL INF = 0x3f3f3f3f3f3f3f3fLL; 40 41 LL t; 42 43 int main(){ 44 scanf("%lld",&t); 45 if(t <= 2) { 46 puts("-1"); 47 return 0; 48 } 49 for(int i = 3; i <= sqrt(t); i++) { 50 if(t % i == 0) { 51 LL tmp = t / i; 52 LL x = 1LL * i * i; 53 if(x & 1) { 54 printf("%lld %lld\n",(1LL * i * i - 1) / 2 * tmp,(1LL * i * i + 1) / 2 * tmp); 55 return 0; 56 } 57 } 58 } 59 LL num = 1; 60 while(t % 2 == 0) { 61 num = num * 2; 62 t /= 2; 63 } 64 if(t == 1) { 65 t = 4; 66 num /= 4; 67 printf("%lld %lld\n",3 * num,5 * num); 68 } else { 69 printf("%lld %lld\n",(t * t - 1) / 2 * num,(t * t + 1) / 2 * num); 70 } 71 return 0; 72 }
A. Counterexample (Codeforces Round #275(div2)
Note In the first sample pair (2,?4) is not coprime and pairs (2,?3) and (3,?4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000
Note
In the first sample pair (2,?4) is not coprime and pairs (2,?3) and (3,?4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
找出3个数,前两个的最大公约数为1,后两个最大公约数为1,第1个和第3个的最大公约数不为1.
由于题目中说了,r-l
代码:
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; long long gcd(long long a,long long b) { return b==0?a:gcd(b,a%b); } int main() { long long l,r; long long x,y,z; int sign=0; scanf("%I64d%I64d",&l,&r); for(long long i=l;i<br><br></cstring></algorithm></cstdio></iostream>
B. Friends and Presents(Codeforces Round #275(div2)
Note In the first sample you give the set of numbers {1,?3,?5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1,?3,?5} to the first friend, then we cannot give any of the numbers 1 , 3 , 5 t
Note
In the first sample you give the set of numbers {1,?3,?5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1,?3,?5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.
In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1,?2,?4} to the second friend. Thus, the answer to the problem is 4.
二分渣渣把二分又写跪了,总是分不清l与r的关系o(╯□╰)o,我竟然l和r都判断了一下。这题竟然l和r都能过。
这题就是枚举一下中间结果,对a周期为x-1,b周期为y-1,只有当i为y的倍数时,只能让a取,当i为x的倍数时,只
能让b取,算一下x,y的倍数时两个都不能取得,a的总数量减去只能a取的,b的总数量减去只能b取的 ,剩下的要
取的和小于等于两个都能取得,这个值就是有效值。
代码:
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; long long cnt1,cnt2,x,y; long long gcd(long long a,long long b) { return b==0?a:gcd(b,a%b); } bool judge(long long v) { long long t1,t2,t3; t1=v/x; t2=v/y; t3=v/(x*y/gcd(x,y)); long long temp1,temp2,temp3; temp1=max((long long)0,cnt1-t2+t3);//t2-t3是只能a取的,cnt1-只能a取的,就是剩下a没取的 temp2=max((long long)0,cnt2-t1+t3);//t1-t3是只能b取的,cnt2-只能b取的,就是剩下b没取的 temp3=max((long long)0,v-t1-t2+t3);//x,y都能取的 if(temp3>=temp1+temp2)//a,b都能取的大于要大于等于a,b没取的和 return true; else return false; } int main() { scanf("%I64d%I64d%I64d%I64d",&cnt1,&cnt2,&x,&y); long long l=1,r=2000000000; long long u=0; while(l<r int m="(l+r)">>1; if(judge(m)) { u=m; r=m; } else { l=m+1; } } // long long ans; // if(judge(r)) // ans=r; // else // ans=l; printf("%I64d\n",u); return 0; }</r></algorithm></cstdio></iostream>
B. Friends and Presents(Codeforces Round #275(div2)_html/css_WEB-ITnose
B. Friends and Presents
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
you have two friends. you want to present each of them several positive integers. you want to present cnt1 numbers to the first friend andcnt2 numbers to the second friend. moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you''re not going to present your friends numbers they don''t like.
Your task is to find such minimum number v, that you can form presents using numbers from a set 1,?2,?...,?v. Of course you may choose not to present some numbers at all.
A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.
Input
The only line contains four positive integers cnt1, cnt2, x, y (1?≤?cnt1,?cnt2?109; cnt1?+?cnt2?≤?109; 2?≤?x?
立即学习“前端免费学习笔记(深入)”;
Output
Print a single integer ? the answer to the problem.
Sample test(s)
input
3 1 2 3
output
input
1 3 2 3
output
Note
In the first sample you give the set of numbers {1,?3,?5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1,?3,?5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.
In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1,?2,?4} to the second friend. Thus, the answer to the problem is 4.
二分渣渣把二分又写跪了,总是分不清l与r的关系o(?□?)o,我竟然l和r都判断了一下。这题竟然l和r都能过。
这题就是枚举一下中间结果,对a周期为x-1,b周期为y-1,只有当i为y的倍数时,只能让a取,当i为x的倍数时,只
能让b取,算一下x,y的倍数时两个都不能取得,a的总数量减去只能a取的,b的总数量减去只能b取的 ,剩下的要
取的和小于等于两个都能取得,这个值就是有效值。
代码:
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;long long cnt1,cnt2,x,y;long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}bool judge(long long v){ long long t1,t2,t3; t1=v/x; t2=v/y; t3=v/(x*y/gcd(x,y)); long long temp1,temp2,temp3; temp1=max((long long)0,cnt1-t2+t3);//t2-t3是只能a取的,cnt1-只能a取的,就是剩下a没取的 temp2=max((long long)0,cnt2-t1+t3);//t1-t3是只能b取的,cnt2-只能b取的,就是剩下b没取的 temp3=max((long long)0,v-t1-t2+t3);//x,y都能取的 if(temp3>=temp1+temp2)//a,b都能取的大于要大于等于a,b没取的和 return true; else return false;}int main(){ scanf("%I64d%I64d%I64d%I64d",&cnt1,&cnt2,&x,&y); long long l=1,r=2000000000; long long u=0; while(l<r int m="(l+r)">>1; if(judge(m)) { u=m; r=m; } else { l=m+1; } } // long long ans; // if(judge(r)) // ans=r; // else // ans=l; printf("%I64d\n",u); return 0;}</r></algorithm></cstdio></iostream>
C. Book Reading (Codeforces Round #582 (Div. 3))
polycarp is reading a book consisting of nn pages numbered from 11 to nn. Every time he finishes the page with the number divisible by mm,he writes down the last digit of this page number. For example,if n=15n=15 and m=5m=5,pages divisible by mm are 5,10,155,10,15. Their last digits are 5,0,55,5 correspondingly,their sum is 1010.
Your task is to calculate the sum of all digits polycarp has written down.
You have to answer qq independent queries.
The first line of the input contains one integer qq (1≤q≤10001≤q≤1000) — the number of queries.
The following qq lines contain queries,one per line. Each query is given as two integers nn and mm (1≤n,m≤10161≤n,m≤1016) — the number of pages in the book and required divisor,respectively.
For each query print the answer for it — the sum of digits written down by polycarp.
7 1 1 10 1 100 3 1024 14 998244353 1337 123 144 1234312817382646 13
1 45 153 294 3359835 0 427262129093995
分析:计算出n范围内m的个位数的倍数的个位数的和
#include <bits/stdc++.h> #define TOP 10001 using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); map<int,vector<int> > r; int q; ll m,n,coc,rest,fin,ans; vector<int> aux; r[1] = {1,2,3,4,5,6,7,8,9,0}; r[2] = {2,0}; r[3] = {3,1,0}; r[4] = {4,0}; r[5] = {5,0}; r[6] = {6,0}; r[7] = {7,0}; r[8] = {8,0}; r[9] = {9,0}; cin >> q; while(q--){ cin >> n >> m; coc = n / m; fin = m % 10; ans = 0; if(fin != 0){ aux = r[fin]; n = aux.size(); rest = coc % n; coc /= n; for(int i = 0; i < n; ++i) ans += aux[i] * (coc + (i < rest)); } cout << ans << ‘\n‘; } return 0; }
我们今天的关于Pythagorean Triples和Codeforces Round #368 (Div. 2) + 构建直角三角形的分享就到这里,谢谢您的阅读,如果想了解更多关于A. Counterexample (Codeforces Round #275(div2)、B. Friends and Presents(Codeforces Round #275(div2)、B. Friends and Presents(Codeforces Round #275(div2)_html/css_WEB-ITnose、C. Book Reading (Codeforces Round #582 (Div. 3))的相关信息,可以在本站进行搜索。
本文标签: