日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #716 (Div. 2) (位运算AND)

發布時間:2025/3/19 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #716 (Div. 2) (位运算AND) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

B. AND 0, Sum Big

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Baby Badawy’s first words were “AND 0 SUM BIG”, so he decided to solve the following problem. Given two integers n and k, count the number of arrays of length n such that:

all its elements are integers between 0 and 2k?1 (inclusive);
the bitwise AND of all its elements is 0;
the sum of its elements is as large as possible.
Since the answer can be very large, print its remainder when divided by 109+7.

Input
The first line contains an integer t (1≤t≤10) — the number of test cases you need to solve.

Each test case consists of a line containing two integers n and k (1≤n≤105, 1≤k≤20).

Output
For each test case, print the number of arrays satisfying the conditions. Since the answer can be very large, print its remainder when divided by 109+7.

Example
inputCopy
2
2 2
100000 20
outputCopy
4
226732710
Note
In the first example, the 4 arrays are:

[3,0],
[0,3],
[1,2],
[2,1].



#include <bits/stdc++.h> using namespace std; const int mod = 1e9+7; typedef long long ll; int main(){int t; cin>>t;while(t--){ll n,k; cin>>n>>k;ll ans = 1;for(int i=1; i<=k; i++){ans*=n; ans%=mod; //具體分到每一步都取模}cout<<ans<<endl;}return 0; }

C. Product 1 Modulo N

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Now you get Baby Ehab’s first words: “Given an integer n, find the longest subsequence of [1,2,…,n?1] whose product is 1 modulo n.” Please solve the problem.

A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly all) elements. The product of an empty subsequence is equal to 1.

Input
The only line contains the integer n (2≤n≤105).

Output
The first line should contain a single integer, the length of the longest subsequence.

The second line should contain the elements of the subsequence, in increasing order.

If there are multiple solutions, you can print any.

Examples
inputCopy
5
outputCopy
3
1 2 3
inputCopy
8
outputCopy
4
1 3 5 7
Note
In the first example, the product of the elements is 6 which is congruent to 1 modulo 5. The only longer subsequence is [1,2,3,4]. Its product is 24 which is congruent to 4 modulo 5. Hence, the answer is [1,2,3].


只能選與n互質的數,
設s為所有與n互質的數的積對n取模的結果,
如果s=1,那么這些數全部可以選擇,
如果s!=1,此時s一定與n互質,因此s也在這些數中,
那么選除了s的其他數就行了.

#include <bits/stdc++.h> using namespace std; typedef long long ll; ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b); } int main(){vector<ll>ve;ll ans = 1;ll n; cin>>n;for(int i=1; i<n; i++){if(gcd(i,n)==1){ve.push_back(i); ans*=i; ans%=n;}}if(ans%n!=1) ve.pop_back();cout<<ve.size()<<endl;for(int i=0; i<ve.size(); i++) cout<<ve[i]<<" ";return 0; }

總結

以上是生活随笔為你收集整理的Codeforces Round #716 (Div. 2) (位运算AND)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。