当前位置: 首页 > news >正文

A Research Problem UVA - 10837 欧拉函数逆应用

平时看到的题目是给n求phi(n) 现在是给phi(n)求一个最小n

当一个数为素数是m=n*(1-1/n);

例如 12=13(1-1/13);所以可以得出 m%(n-1)==0 时,n-1为n的素因子

m=n*(1-1/p1)*(1-1/pn);

n=p1^x1*(p1-1)*p2^x2(p2-1)......;

#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <memory.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define ll long long
#define INF 1000000
#include<time.h>

using namespace std;
#define ll long long
#define maxn 10005
#define ULL unsigned long long
#define MST(vis,x) memset(vis,x,sizeof(vis))
#define tempmaxn 200000000

int vis[maxn];
int prim[maxn];
int all;
void init()
{
    all=1;
    for(int a=2; a<=10000; a++)
    {
        if(vis[a]==0)
            prim[all++]=a;
        for(int b=1; b<all&&prim[b]*a<=10000; b++)
        {
            vis[prim[b]*a]=1;
            if(a%prim[b]==0)break;
        }
    }
    return;
}
int ans;
int s1[maxn],vs[maxn];
int op;
void getprim(int n)
{
    for(int a=1; (a<all)&&(prim[a]-1)*(prim[a]-1)<=n; a++)
        if(n%(prim[a]-1)==0)
            s1[op++]=prim[a];
    return;
}
bool judge(int n)
{
    if(n==2)return true;
    for(int a=1;a<all&&prim[a]*prim[a]<=n;a++)
        if(n%prim[a]==0)
            return false;
    for(int a=1;a<op;a++)
        if(vs[a]&&s1[a]==n)
            return false;
    return true;
}
void cir(int tempsum,int tempn,int tempop)
{
    if(tempop==op)
    {
        if(judge(tempn+1))
        {
            if(tempn==1)
                tempn=0;
            ans=min(ans,tempsum*(tempn+1));
        }
        return;
    }
    cir(tempsum,tempn,tempop+1);
    if(tempn%(s1[tempop]-1)==0)
    {
        vs[tempop]=1;
        tempn/=(s1[tempop]-1);
        tempsum*=s1[tempop];
        while(true)
        {
            cir(tempsum,tempn,tempop+1);
            if(tempn%s1[tempop]==0)
            {
                tempn/=s1[tempop];
                tempsum*=s1[tempop];
            }
            else return ;
        }
        vs[op]=0;
    }
    return;
}
int solve(int n)
{
    ans=0x3f3f3f3f;
    op=1;
    MST(vs,0);
    MST(s1,0);
    getprim(n);
    cir(1,n,1);
    if(ans==INF)ans=0;
    return ans;
}
int main()
{
    init();
    int n,i=1;
    while(scanf("%d",&n)!=EOF)
    {
        if(!n)break;
        printf("Case %d: %d %d\n",i++,n,solve(n));
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/tuquanrong/p/7504576.html

相关文章:

  • 洛谷P2344 奶牛抗议
  • python归档:笔记转化
  • 理解JS中的call、apply、bind方法
  • Number Math
  • 初学JAVA的变量作用域
  • Inno Setup自定义安装界面脚本
  • Spring AOP简单的配置(注解和xml配置)
  • Swift,枚举
  • java操作Excel
  • 'NoneType' object is not iterable
  • AngularJS
  • C++ 清空队列(queue)的几种方法
  • MIME 类型(HttpContext.Response.ContentType)列表
  • 从微信官方获取微信公众号名片:https://open.weixin.qq.com/qr/code?username=haihongruanjian...
  • 分享 - 27 个机器学习、数学、Python 速查表
  • es6(二):字符串的扩展
  • ESLint简单操作
  • Hibernate最全面试题
  • IDEA 插件开发入门教程
  • Java IO学习笔记一
  • JSDuck 与 AngularJS 融合技巧
  • leetcode98. Validate Binary Search Tree
  • supervisor 永不挂掉的进程 安装以及使用
  • TypeScript迭代器
  • 前端 CSS : 5# 纯 CSS 实现24小时超市
  • 区块链将重新定义世界
  • 学习使用ExpressJS 4.0中的新Router
  • 这几个编码小技巧将令你 PHP 代码更加简洁
  • 阿里云服务器购买完整流程
  • (20050108)又读《平凡的世界》
  • (9)STL算法之逆转旋转
  • (翻译)Entity Framework技巧系列之七 - Tip 26 – 28
  • (简单有案例)前端实现主题切换、动态换肤的两种简单方式
  • (学习日记)2024.02.29:UCOSIII第二节
  • (原創) 物件導向與老子思想 (OO)
  • (转)jQuery 基础
  • (转)Linux下编译安装log4cxx
  • (转)ORM
  • (转)关于pipe()的详细解析
  • (转)平衡树
  • .NET 常见的偏门问题
  • .NET 发展历程
  • .net操作Excel出错解决
  • .net反混淆脱壳工具de4dot的使用
  • .NET中使用Redis (二)
  • @ModelAttribute注解使用
  • [ C++ ] STL---仿函数与priority_queue
  • [ 攻防演练演示篇 ] 利用通达OA 文件上传漏洞上传webshell获取主机权限
  • [acwing周赛复盘] 第 69 场周赛20220917
  • [Angular] 笔记 21:@ViewChild
  • [AutoSar NVM] 存储架构
  • [BZOJ 3680]吊打XXX(模拟退火)
  • [C++]C++基础知识概述
  • [C++11 多线程同步] --- 条件变量的那些坑【条件变量信号丢失和条件变量虚假唤醒(spurious wakeup)】
  • [CC2642r1] ble5 stacks 蓝牙协议栈 介绍和理解