zoukankan      html  css  js  c++  java
  • Codeforces Round #716 (Div. 2) C. Product 1 Modulo N

    Now you get Baby Ehab's first words: "Given an integer nn, find the longest subsequence of [1,2,,n1][1,2,…,n−1] whose product is 11 modulo nn." Please solve the problem.

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

    Input

    The only line contains the integer nn (2n1052≤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.

    #include<bits/stdc++.h>
    #define ll long long int
    using namespace std;
    const ll mod = 1e9+7;
    int vis[100010];
    int main()
    {
        int n;
        cin>>n;
        ll sum = 1;
        int ans = 0;
        for(int i=1;i<n;i++)
        {
            if(__gcd(i,n) == 1)
            {
                vis[i] = 1;
                sum = sum*i%n;
                ans++;
            }
        }
        if(sum!=1) 
        {
            ans--;
            vis[sum] = 0;
        }
        cout<<ans<<endl;
        for(int i=1;i<n;i++)
        {
            if(vis[i]) cout<<i<<" ";
        }
    }
  • 相关阅读:
    Struts数据效验
    Struts2中国际化
    ValueStack对象
    Ognl表达式语言
    Struts2拦截器
    ubuntu下tomcat运行不起来解决
    Windows 下的SSH客户端
    远程管理控制ssh
    linux用户和组账户管理
    搭建Java服务器,并且实现远程安全访问linux系统
  • 原文地址:https://www.cnblogs.com/lcsdsg/p/14695566.html
Copyright © 2011-2022 走看看